fuzz: fix memory allocation failure logic (#1867)
We *do* want to have some allocation errors.
Fix some related bugs
Fix: 29be01ef
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
#include <stdio.h>
|
||||
#include "fuzzer/FuzzedDataProvider.h"
|
||||
|
||||
struct ndpi_detection_module_struct *ndpi_info_mod = NULL;
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
FuzzedDataProvider fuzzed_data(data, size);
|
||||
u_int16_t i, num_values, num_learning_values, max_series_len;
|
||||
@@ -27,11 +25,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if(fuzzed_data.remaining_bytes() < 1024)
|
||||
return -1;
|
||||
|
||||
/* We don't really need the detection module, but this way we can enable
|
||||
memory allocation failures */
|
||||
if (ndpi_info_mod == NULL) {
|
||||
fuzz_init_detection_module(&ndpi_info_mod, 0);
|
||||
}
|
||||
/* To allow memory allocation failures */
|
||||
fuzz_set_alloc_callbacks_and_seed(size);
|
||||
|
||||
/* Data set */
|
||||
num_values = fuzzed_data.ConsumeIntegral<u_int8_t>();
|
||||
@@ -84,6 +79,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
ndpi_data_window_stddev(a);
|
||||
ndpi_data_entropy(a);
|
||||
ndpi_reset_data_analysis(a);
|
||||
ndpi_data_last(a);
|
||||
|
||||
/* Data ratio */
|
||||
if (num_values > 1)
|
||||
ndpi_data_ratio2str(ndpi_data_ratio(values[0], values[1]));
|
||||
|
||||
/* Done. Free */
|
||||
if (rc_hw == 0)
|
||||
|
||||
Reference in New Issue
Block a user