mirror of
https://github.com/vel21ripn/nDPI.git
synced 2026-05-20 09:23:49 +00:00
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.
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#include "ndpi_api.h"
|
|
#include "fuzz_common_code.h"
|
|
#include "reader_util.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "fuzzer/FuzzedDataProvider.h"
|
|
|
|
u_int8_t enable_payload_analyzer = 0;
|
|
u_int8_t enable_flow_stats = 0;
|
|
u_int8_t human_readeable_string_len = 5;
|
|
u_int8_t max_num_udp_dissected_pkts = 16 /* 8 is enough for most protocols, Signal requires more */, max_num_tcp_dissected_pkts = 80 /* due to telnet */;
|
|
int malloc_size_stats = 0;
|
|
FILE *fingerprint_fp = NULL;
|
|
bool do_load_lists = false;
|
|
char *addr_dump_path = NULL;
|
|
int monitoring_enabled = 0;
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|
FuzzedDataProvider fuzzed_data(data, size);
|
|
int inverted_logic;
|
|
NDPI_INTERNAL_PROTOCOL_BITMASK bitmask;
|
|
char *str;
|
|
|
|
/* To allow memory allocation failures */
|
|
fuzz_set_alloc_callbacks_and_seed(size);
|
|
|
|
inverted_logic = size % 2; /* pseudo-random */
|
|
if(inverted_logic) {
|
|
NDPI_INTERNAL_PROTOCOL_SET_ALL(bitmask);
|
|
} else {
|
|
NDPI_INTERNAL_PROTOCOL_RESET(bitmask);
|
|
}
|
|
|
|
str = (char *)ndpi_malloc(size + 1); /* We need a null-terminated string */
|
|
if(str) {
|
|
memcpy(str, data, size);
|
|
str[size] = '\0';
|
|
|
|
parse_proto_name_list(str, &bitmask, inverted_logic);
|
|
|
|
ndpi_free(str);
|
|
}
|
|
return 0;
|
|
}
|