blob: 1181b1593371704cff3e3d8c6ee7f9daf43899e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "ndpi_api.h"
#include "fuzz_common_code.h"
#include <stdint.h>
#include "fuzzer/FuzzedDataProvider.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fuzzed_data(data, size);
struct ndpi_cm_sketch *sketch;
u_int16_t i, num_hashes, num_iteration, num_lookup;
/* Just to have some data */
if (fuzzed_data.remaining_bytes() < 1024)
return -1;
/* To allow memory allocation failures */
fuzz_set_alloc_callbacks_and_seed(size);
num_hashes = fuzzed_data.ConsumeIntegralInRange(0, 8192);
num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
num_lookup = fuzzed_data.ConsumeIntegral<u_int8_t>();
sketch = ndpi_cm_sketch_init(num_hashes);
if (sketch) {
for (i = 0; i < num_iteration; i++) {
ndpi_cm_sketch_add(sketch, fuzzed_data.ConsumeIntegral<u_int32_t>());
}
for (i = 0; i < num_lookup; i++) {
ndpi_cm_sketch_count(sketch, fuzzed_data.ConsumeIntegral<u_int32_t>());
}
ndpi_cm_sketch_destroy(sketch);
}
return 0;
}
|