aboutsummaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2022-05-07 09:26:09 +0200
committerGitHub <noreply@github.com>2022-05-07 09:26:09 +0200
commit87f93ea4fd86da8bcfd75b7d74b49dce720d8ef6 (patch)
tree23cc9dae2eb4ee0136c731806b85294cae80e28c /fuzz
parent2e0dedbaae24a8662a494e15fe47a67ea30fdcec (diff)
Replaced ndpiReader's libjson-c support with libnDPI's internal serialization interface. (#1535)
* Fixes #1528 * Serialization Interface should also fuzzed * libjson-c may only be used in the unit test to verify the internal serialization interface * Serialization Interface supports tlv(broken), csv and json * Unit test does work again and requires libjson-c Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/fuzz_ndpi_reader.c6
-rw-r--r--fuzz/fuzz_process_packet.c21
2 files changed, 23 insertions, 4 deletions
diff --git a/fuzz/fuzz_ndpi_reader.c b/fuzz/fuzz_ndpi_reader.c
index 878896bca..abf5a6743 100644
--- a/fuzz/fuzz_ndpi_reader.c
+++ b/fuzz/fuzz_ndpi_reader.c
@@ -60,7 +60,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
prefs->max_ndpi_flows = 1024 * 1024;
prefs->quiet_mode = 0;
- workflow = ndpi_workflow_init(prefs, NULL /* pcap handler will be set later */, 0);
+ 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);
ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &all);
@@ -79,6 +79,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (pkts == NULL) {
remove(pcap_path);
free(pcap_path);
+ ndpi_term_serializer(&workflow->ndpi_serializer);
return 0;
}
if (ndpi_is_datalink_supported(pcap_datalink(pkts)) == 0)
@@ -87,6 +88,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
pcap_close(pkts);
remove(pcap_path);
free(pcap_path);
+ ndpi_term_serializer(&workflow->ndpi_serializer);
return 0;
}
@@ -104,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
ndpi_risk flow_risk;
memcpy(packet_checked, pkt, header->caplen);
- ndpi_workflow_process_packet(workflow, header, packet_checked, &flow_risk, NULL);
+ ndpi_workflow_process_packet(workflow, header, packet_checked, &flow_risk);
free(packet_checked);
}
diff --git a/fuzz/fuzz_process_packet.c b/fuzz/fuzz_process_packet.c
index 8841c0a1c..e4f4bcf78 100644
--- a/fuzz/fuzz_process_packet.c
+++ b/fuzz/fuzz_process_packet.c
@@ -4,6 +4,8 @@
#include <stdio.h>
struct ndpi_detection_module_struct *ndpi_info_mod = NULL;
+static ndpi_serializer json_serializer = {};
+static ndpi_serializer csv_serializer = {};
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
uint8_t protocol_was_guessed;
@@ -17,12 +19,27 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
ndpi_set_log_level(ndpi_info_mod, 4);
ndpi_set_debug_bitmask(ndpi_info_mod, debug_bitmask);
ndpi_finalize_initialization(ndpi_info_mod);
+ ndpi_init_serializer(&json_serializer, ndpi_serialization_format_json);
+ ndpi_init_serializer(&csv_serializer, ndpi_serialization_format_csv);
}
struct ndpi_flow_struct *ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT);
memset(ndpi_flow, 0, SIZEOF_FLOW_STRUCT);
- ndpi_detection_process_packet(ndpi_info_mod, ndpi_flow, Data, Size, 0);
- ndpi_detection_giveup(ndpi_info_mod, ndpi_flow, 1, &protocol_was_guessed);
+ ndpi_protocol detected_protocol =
+ ndpi_detection_process_packet(ndpi_info_mod, ndpi_flow, Data, Size, 0);
+ ndpi_protocol guessed_protocol =
+ ndpi_detection_giveup(ndpi_info_mod, ndpi_flow, 1, &protocol_was_guessed);
+
+ ndpi_reset_serializer(&json_serializer);
+ ndpi_reset_serializer(&csv_serializer);
+ if (protocol_was_guessed == 0)
+ {
+ ndpi_dpi2json(ndpi_info_mod, ndpi_flow, detected_protocol, &json_serializer);
+ ndpi_dpi2json(ndpi_info_mod, ndpi_flow, detected_protocol, &csv_serializer);
+ } else {
+ ndpi_dpi2json(ndpi_info_mod, ndpi_flow, guessed_protocol, &json_serializer);
+ ndpi_dpi2json(ndpi_info_mod, ndpi_flow, guessed_protocol, &csv_serializer);
+ }
ndpi_free_flow(ndpi_flow);
return 0;