/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 | 664 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
13 | | |
14 | | /* This one must not return shared compressor, or above 13 */ |
15 | 664 | { |
16 | 664 | auto [negCompression, negCompressionWindow, negInflationWindow, response] = uWS::negotiateCompression(true, 13, 0, std::string_view((char *) data, size)); |
17 | | |
18 | 664 | if (negCompression) { |
19 | | /* If we want dedicated compression, we must not end up here! */ |
20 | 89 | free((void *) (negCompressionWindow == 0)); |
21 | | |
22 | | /* Some more checks (freeing 0 does nothing) */ |
23 | 89 | free((void *) (negCompressionWindow > 13)); |
24 | 89 | free((void *) (negInflationWindow != 0)); |
25 | 89 | free((void *) (negInflationWindow < 0 || negInflationWindow > 15 || negCompressionWindow < 0 || negCompressionWindow > 15)); |
26 | 89 | } |
27 | 664 | } |
28 | | |
29 | | /* This one must not return anything over 0 (only shared) */ |
30 | 664 | { |
31 | 664 | auto [negCompression, negCompressionWindow, negInflationWindow, response] = uWS::negotiateCompression(true, 0, 0, std::string_view((char *) data, size)); |
32 | | |
33 | 664 | if (negCompression) { |
34 | | /* If we want shared compression, we must not end up here! */ |
35 | 99 | free((void *) (negCompressionWindow != 0)); |
36 | 99 | } |
37 | 664 | } |
38 | | |
39 | | |
40 | | /* Whatever, this one must not negotiate anything */ |
41 | 664 | { |
42 | 664 | auto [negCompression, negCompressionWindow, negInflationWindow, response] = uWS::negotiateCompression(false, 13, 15, std::string_view((char *) data, size)); |
43 | | |
44 | 664 | if (negCompression) { |
45 | 0 | free((void *) -1); |
46 | 0 | } |
47 | 664 | } |
48 | | |
49 | 664 | return 0; |
50 | 664 | } |
51 | | |