/src/uWebSockets/fuzzing/helpers.h
Line | Count | Source |
1 | | #ifndef HELPERS_H |
2 | | #define HELPERS_H |
3 | | |
4 | | /* Common helpers for fuzzing */ |
5 | | |
6 | | #include <functional> |
7 | | #include <string_view> |
8 | | #include <cstring> |
9 | | |
10 | | /* We use this to pad the fuzz */ |
11 | 11.0k | static inline const uint8_t *makePadded(const uint8_t *data, size_t size) { |
12 | 11.0k | static int paddedLength = 512 * 1024; |
13 | 11.0k | static char *padded = new char[128 + paddedLength + 128]; |
14 | | |
15 | | /* Increase landing area if required */ |
16 | 11.0k | if (paddedLength < size) { |
17 | 93 | delete [] padded; |
18 | 93 | paddedLength = size; |
19 | 93 | padded = new char [128 + paddedLength + 128]; |
20 | 93 | } |
21 | | |
22 | 11.0k | memcpy(padded + 128, data, size); |
23 | | |
24 | 11.0k | return (uint8_t *) padded + 128; |
25 | 11.0k | } TopicTree.cpp:makePadded(unsigned char const*, unsigned long) Line | Count | Source | 11 | 3.40k | static inline const uint8_t *makePadded(const uint8_t *data, size_t size) { | 12 | 3.40k | static int paddedLength = 512 * 1024; | 13 | 3.40k | static char *padded = new char[128 + paddedLength + 128]; | 14 | | | 15 | | /* Increase landing area if required */ | 16 | 3.40k | if (paddedLength < size) { | 17 | 22 | delete [] padded; | 18 | 22 | paddedLength = size; | 19 | 22 | padded = new char [128 + paddedLength + 128]; | 20 | 22 | } | 21 | | | 22 | 3.40k | memcpy(padded + 128, data, size); | 23 | | | 24 | 3.40k | return (uint8_t *) padded + 128; | 25 | 3.40k | } |
Http.cpp:makePadded(unsigned char const*, unsigned long) Line | Count | Source | 11 | 5.87k | static inline const uint8_t *makePadded(const uint8_t *data, size_t size) { | 12 | 5.87k | static int paddedLength = 512 * 1024; | 13 | 5.87k | static char *padded = new char[128 + paddedLength + 128]; | 14 | | | 15 | | /* Increase landing area if required */ | 16 | 5.87k | if (paddedLength < size) { | 17 | 35 | delete [] padded; | 18 | 35 | paddedLength = size; | 19 | 35 | padded = new char [128 + paddedLength + 128]; | 20 | 35 | } | 21 | | | 22 | 5.87k | memcpy(padded + 128, data, size); | 23 | | | 24 | 5.87k | return (uint8_t *) padded + 128; | 25 | 5.87k | } |
PerMessageDeflate.cpp:makePadded(unsigned char const*, unsigned long) Line | Count | Source | 11 | 306 | static inline const uint8_t *makePadded(const uint8_t *data, size_t size) { | 12 | 306 | static int paddedLength = 512 * 1024; | 13 | 306 | static char *padded = new char[128 + paddedLength + 128]; | 14 | | | 15 | | /* Increase landing area if required */ | 16 | 306 | if (paddedLength < size) { | 17 | 24 | delete [] padded; | 18 | 24 | paddedLength = size; | 19 | 24 | padded = new char [128 + paddedLength + 128]; | 20 | 24 | } | 21 | | | 22 | 306 | memcpy(padded + 128, data, size); | 23 | | | 24 | 306 | return (uint8_t *) padded + 128; | 25 | 306 | } |
WebSocket.cpp:makePadded(unsigned char const*, unsigned long) Line | Count | Source | 11 | 1.46k | static inline const uint8_t *makePadded(const uint8_t *data, size_t size) { | 12 | 1.46k | static int paddedLength = 512 * 1024; | 13 | 1.46k | static char *padded = new char[128 + paddedLength + 128]; | 14 | | | 15 | | /* Increase landing area if required */ | 16 | 1.46k | if (paddedLength < size) { | 17 | 12 | delete [] padded; | 18 | 12 | paddedLength = size; | 19 | 12 | padded = new char [128 + paddedLength + 128]; | 20 | 12 | } | 21 | | | 22 | 1.46k | memcpy(padded + 128, data, size); | 23 | | | 24 | 1.46k | return (uint8_t *) padded + 128; | 25 | 1.46k | } |
|
26 | | |
27 | | /* Splits the fuzz data in one or many chunks */ |
28 | 11.0k | static inline void makeChunked(const uint8_t *data, size_t size, std::function<void(const uint8_t *data, size_t size)> cb) { |
29 | | /* First byte determines chunk size; 0 is all that remains, 1-255 is small chunk */ |
30 | 4.15M | for (int i = 0; i < size; ) { |
31 | 4.14M | unsigned int chunkSize = data[i++]; |
32 | 4.14M | if (!chunkSize) { |
33 | 3.54k | chunkSize = size - i; |
34 | 4.14M | } else { |
35 | 4.14M | chunkSize = std::min<int>(chunkSize, size - i); |
36 | 4.14M | } |
37 | | |
38 | 4.14M | cb(data + i, chunkSize); |
39 | 4.14M | i += chunkSize; |
40 | 4.14M | } |
41 | 11.0k | } TopicTree.cpp:makeChunked(unsigned char const*, unsigned long, std::__1::function<void (unsigned char const*, unsigned long)>) Line | Count | Source | 28 | 3.40k | static inline void makeChunked(const uint8_t *data, size_t size, std::function<void(const uint8_t *data, size_t size)> cb) { | 29 | | /* First byte determines chunk size; 0 is all that remains, 1-255 is small chunk */ | 30 | 3.75M | for (int i = 0; i < size; ) { | 31 | 3.74M | unsigned int chunkSize = data[i++]; | 32 | 3.74M | if (!chunkSize) { | 33 | 311 | chunkSize = size - i; | 34 | 3.74M | } else { | 35 | 3.74M | chunkSize = std::min<int>(chunkSize, size - i); | 36 | 3.74M | } | 37 | | | 38 | 3.74M | cb(data + i, chunkSize); | 39 | 3.74M | i += chunkSize; | 40 | 3.74M | } | 41 | 3.40k | } |
Http.cpp:makeChunked(unsigned char const*, unsigned long, std::__1::function<void (unsigned char const*, unsigned long)>) Line | Count | Source | 28 | 5.87k | static inline void makeChunked(const uint8_t *data, size_t size, std::function<void(const uint8_t *data, size_t size)> cb) { | 29 | | /* First byte determines chunk size; 0 is all that remains, 1-255 is small chunk */ | 30 | 202k | for (int i = 0; i < size; ) { | 31 | 196k | unsigned int chunkSize = data[i++]; | 32 | 196k | if (!chunkSize) { | 33 | 2.59k | chunkSize = size - i; | 34 | 193k | } else { | 35 | 193k | chunkSize = std::min<int>(chunkSize, size - i); | 36 | 193k | } | 37 | | | 38 | 196k | cb(data + i, chunkSize); | 39 | 196k | i += chunkSize; | 40 | 196k | } | 41 | 5.87k | } |
PerMessageDeflate.cpp:makeChunked(unsigned char const*, unsigned long, std::__1::function<void (unsigned char const*, unsigned long)>) Line | Count | Source | 28 | 306 | static inline void makeChunked(const uint8_t *data, size_t size, std::function<void(const uint8_t *data, size_t size)> cb) { | 29 | | /* First byte determines chunk size; 0 is all that remains, 1-255 is small chunk */ | 30 | 138k | for (int i = 0; i < size; ) { | 31 | 138k | unsigned int chunkSize = data[i++]; | 32 | 138k | if (!chunkSize) { | 33 | 174 | chunkSize = size - i; | 34 | 137k | } else { | 35 | 137k | chunkSize = std::min<int>(chunkSize, size - i); | 36 | 137k | } | 37 | | | 38 | 138k | cb(data + i, chunkSize); | 39 | 138k | i += chunkSize; | 40 | 138k | } | 41 | 306 | } |
WebSocket.cpp:makeChunked(unsigned char const*, unsigned long, std::__1::function<void (unsigned char const*, unsigned long)>) Line | Count | Source | 28 | 1.46k | static inline void makeChunked(const uint8_t *data, size_t size, std::function<void(const uint8_t *data, size_t size)> cb) { | 29 | | /* First byte determines chunk size; 0 is all that remains, 1-255 is small chunk */ | 30 | 65.1k | for (int i = 0; i < size; ) { | 31 | 63.7k | unsigned int chunkSize = data[i++]; | 32 | 63.7k | if (!chunkSize) { | 33 | 469 | chunkSize = size - i; | 34 | 63.2k | } else { | 35 | 63.2k | chunkSize = std::min<int>(chunkSize, size - i); | 36 | 63.2k | } | 37 | | | 38 | 63.7k | cb(data + i, chunkSize); | 39 | 63.7k | i += chunkSize; | 40 | 63.7k | } | 41 | 1.46k | } |
|
42 | | |
43 | | /* Reads all bytes to trigger invalid reads */ |
44 | 115k | static inline void readBytes(std::string_view s) { |
45 | 115k | volatile int sum = 0; |
46 | 463k | for (int i = 0; i < s.size(); i++) { |
47 | 347k | sum += s[i]; |
48 | 347k | } |
49 | 115k | } Unexecuted instantiation: TopicTree.cpp:readBytes(std::__1::basic_string_view<char, std::__1::char_traits<char> >) Http.cpp:readBytes(std::__1::basic_string_view<char, std::__1::char_traits<char> >) Line | Count | Source | 44 | 115k | static inline void readBytes(std::string_view s) { | 45 | 115k | volatile int sum = 0; | 46 | 463k | for (int i = 0; i < s.size(); i++) { | 47 | 347k | sum += s[i]; | 48 | 347k | } | 49 | 115k | } |
Unexecuted instantiation: PerMessageDeflate.cpp:readBytes(std::__1::basic_string_view<char, std::__1::char_traits<char> >) Unexecuted instantiation: WebSocket.cpp:readBytes(std::__1::basic_string_view<char, std::__1::char_traits<char> >) |
50 | | |
51 | | #endif |