From eec5bccabd76162e53ec7b37a1e7dd3309c24f3e Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 30 Jun 2022 13:36:20 +0200 Subject: [PATCH] Fix byte-order issue during ndpiReader tcp/udp src/dst port serialization. Fixes #1608. * fixed possible memory leak caused by an invalid call to `node_proto_guess_walker()` during serialization * execute serialization code while running regression tests Signed-off-by: Toni Uhlig --- example/ndpiReader.c | 6 ++---- tests/do.sh.in | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 9fa63c8bf9f..d7d720fffd0 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -1624,8 +1624,8 @@ static void printFlowSerialized(u_int16_t thread_id, ndpi_serialize_string_float(serializer, "duration_ms", (l-f)/1000.0, "%.3f"); ndpi_serialize_string_string(serializer, "src_name", flow->src_name); ndpi_serialize_string_string(serializer, "dst_name", flow->dst_name); - ndpi_serialize_string_uint32(serializer, "src_port", flow->src_port); - ndpi_serialize_string_uint32(serializer, "dst_port", flow->dst_port); + ndpi_serialize_string_uint32(serializer, "src_port", ntohs(flow->src_port)); + ndpi_serialize_string_uint32(serializer, "dst_port", ntohs(flow->dst_port)); ndpi_serialize_string_uint32(serializer, "ip_version", flow->ip_version); ndpi_serialize_string_uint32(serializer, "vlan_id", flow->vlan_id); ndpi_serialize_string_uint32(serializer, "bidirectional", flow->bidirectional); @@ -3405,8 +3405,6 @@ static void printFlowsStats() { for(i = 0; i < NUM_ROOTS; i++) { ndpi_twalk(ndpi_thread_info[thread_id].workflow->ndpi_flows_root[i], node_print_known_proto_walker, &thread_id); - ndpi_twalk(ndpi_thread_info[thread_id].workflow->ndpi_flows_root[i], - node_proto_guess_walker, &thread_id); ndpi_twalk(ndpi_thread_info[thread_id].workflow->ndpi_flows_root[i], node_print_unknown_proto_walker, &thread_id); } diff --git a/tests/do.sh.in b/tests/do.sh.in index 63d2fa591f0..ba16045a0cb 100755 --- a/tests/do.sh.in +++ b/tests/do.sh.in @@ -45,7 +45,7 @@ build_results() { #echo $f # create result files if not present if [ ! -f result/$f.out ]; then - CMD="$READER -q -t -i pcap/$f -w result/$f.out -v 2" + CMD="$READER -q -K JSON -k /dev/null -t -i pcap/$f -w result/$f.out -v 2" $CMD fi done @@ -73,7 +73,7 @@ check_results() { fi if [ -f result/$f.out ]; then - CMD="$READER -q -t -i pcap/$f -w /tmp/reader.out -v 2" + CMD="$READER -q -K JSON -k /dev/null -t -i pcap/$f -w /tmp/reader.out -v 2" $CMD CMD_RET=$? if [ $CMD_RET -eq 0 ]; then