/src/uWebSockets/fuzzing/Extensions.cpp
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* This is a fuzz test of the websocket extensions parser */  | 
2  |  |  | 
3  |  | #define WIN32_EXPORT  | 
4  |  |  | 
5  |  | #include <cstdio>  | 
6  |  | #include <string>  | 
7  |  | #include <cstdlib>  | 
8  |  |  | 
9  |  | /* We test the websocket extensions parser */  | 
10  |  | #include "../src/WebSocketExtensions.h"  | 
11  |  |  | 
12  | 656  | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 
13  |  |  | 
14  |  |     /* This one must not return shared compressor, or above 13 */  | 
15  | 656  |     { | 
16  | 656  |         auto [negCompression, negCompressionWindow, negInflationWindow, response] = uWS::negotiateCompression(true, 13, 0, std::string_view((char *) data, size));  | 
17  |  |  | 
18  | 656  |         if (negCompression) { | 
19  |  |             /* If we want dedicated compression, we must not end up here! */  | 
20  | 91  |             free((void *) (negCompressionWindow == 0));  | 
21  |  |  | 
22  |  |             /* Some more checks (freeing 0 does nothing) */  | 
23  | 91  |             free((void *) (negCompressionWindow > 13));  | 
24  | 91  |             free((void *) (negInflationWindow != 0));  | 
25  | 91  |             free((void *) (negInflationWindow < 0 || negInflationWindow > 15 || negCompressionWindow < 0 || negCompressionWindow > 15));  | 
26  | 91  |         }  | 
27  | 656  |     }  | 
28  |  |  | 
29  |  |     /* This one must not return anything over 0 (only shared) */  | 
30  | 656  |     { | 
31  | 656  |         auto [negCompression, negCompressionWindow, negInflationWindow, response] = uWS::negotiateCompression(true, 0, 0, std::string_view((char *) data, size));  | 
32  |  |  | 
33  | 656  |         if (negCompression) { | 
34  |  |             /* If we want shared compression, we must not end up here! */  | 
35  | 102  |             free((void *) (negCompressionWindow != 0));  | 
36  | 102  |         }  | 
37  | 656  |     }  | 
38  |  |  | 
39  |  |  | 
40  |  |     /* Whatever, this one must not negotiate anything */  | 
41  | 656  |     { | 
42  | 656  |         auto [negCompression, negCompressionWindow, negInflationWindow, response] = uWS::negotiateCompression(false, 13, 15, std::string_view((char *) data, size));  | 
43  |  |  | 
44  | 656  |         if (negCompression) { | 
45  | 0  |             free((void *) -1);  | 
46  | 0  |         }  | 
47  | 656  |     }  | 
48  |  |  | 
49  | 656  |     return 0;  | 
50  | 656  | }  | 
51  |  |  |