nDPI/fuzz/fuzz_filecfg_config.c
Ivan Nardi 70a72f1638
New API to enable/disable protocols; remove ndpi_set_protocol_detection_bitmask2() (#2853)
The main goal is not to have the bitmask depending on the total number
of protocols anymore: `NDPI_INTERNAL_PROTOCOL_BITMASK` depends only on
internal protocols, i.e. on `NDPI_MAX_INTERNAL_PROTOCOLS`, i.e.
custom-defined protocols are not counted.
See #2136

Keep the old data structure `NDPI_PROTOCOL_BITMASK` with the old
semantic.

Since we need to change the API (and all the application code...)
anyway, simplify the API: by default all the protocols are enabled.
If you need otherwise, please use `ndpi_init_detection_module_ext()`
instead of `ndpi_init_detection_module()` (you can find an example in
the `ndpiReader` code).

To update the application code you likely only need to remove these 3
lines from your code:
```
- NDPI_PROTOCOL_BITMASK all;
- NDPI_BITMASK_SET_ALL(all);
- ndpi_set_protocol_detection_bitmask2(ndpi_str, &all);
```

Removed an unused field and struct definition.
2025-06-03 09:45:46 +02:00

24 lines
612 B
C

#include "ndpi_api.h"
#include "ndpi_private.h"
#include "fuzz_common_code.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
struct ndpi_detection_module_struct *ndpi_struct;
FILE *fd;
/* To allow memory allocation failures */
fuzz_set_alloc_callbacks_and_seed(size);
ndpi_struct = ndpi_init_detection_module(NULL);
ndpi_set_config(ndpi_struct, NULL, "log.level", "3");
ndpi_set_config(ndpi_struct, "all", "log", "1");
fd = buffer_to_file(data, size);
load_config_file_fd(ndpi_struct, fd);
if(fd)
fclose(fd);
ndpi_exit_detection_module(ndpi_struct);
return 0;
}