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:
Ivan Nardi
2023-01-20 14:27:33 +01:00
committed by GitHub
parent 496b284c98
commit 5e8c1ebbb7
280 changed files with 161 additions and 124 deletions
+6 -2
View File
@@ -61,6 +61,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
prefs->max_ndpi_flows = 16 * 1024 * 1024;
prefs->quiet_mode = 0;
#ifdef ENABLE_MEM_ALLOC_FAILURES
fuzz_set_alloc_callbacks();
#endif
workflow = ndpi_workflow_init(prefs, NULL /* pcap handler will be set later */, 0, ndpi_serialization_format_json);
// enable all protocols
NDPI_BITMASK_SET_ALL(all);
@@ -80,12 +84,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
sizeof(workflow->stats.protocol_flows));
ndpi_finalize_initialization(workflow->ndpi_struct);
}
#ifdef ENABLE_MEM_ALLOC_FAILURES
/* Don't fail memory allocations until init phase is done */
set_mem_alloc_state(Size);
fuzz_set_alloc_seed(Size);
#endif
fd = bufferToFile(Data, Size);
if (fd == NULL)
return 0;