aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2021-02-10 15:24:11 +0100
committerGitHub <noreply@github.com>2021-02-10 15:24:11 +0100
commit1e12c90c66c6ea720fd87e2dca61e0d15a38ca3a (patch)
tree53945f4a800b3246a74aa2df0bc3e9cf50878a1a
parentc408df1b0efbfd75e7d2433472589cd283a5e4c5 (diff)
Fixed memory leaks caused by conditional free'ing for some TLS connec… (#1132)
* Fixed memory leaks caused by conditional free'ing for some TLS connections. * Members of tls_quic struct should also free'd if the detected master protocol is IMAPS / POPS / SMTPS / etc. Signed-off-by: Toni Uhlig <matzeton@googlemail.com> * Prevent reader_util.c from exit()'ing if maximum flow count reached. This confuses the fuzzer. * Improved fuzz/Makefile.am to use LDADD for ../example/libndpiReader.a instead of LDFLAGS. That way, fuzz_ndpi_reader re-links to ../example/libndpiReader.a if something changed there. Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--example/reader_util.c2
-rw-r--r--fuzz/Makefile.am4
-rw-r--r--src/lib/ndpi_main.c14
3 files changed, 10 insertions, 10 deletions
diff --git a/example/reader_util.c b/example/reader_util.c
index 86ddf6ad2..e2a691576 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -812,7 +812,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
LOG(NDPI_LOG_ERROR,
"maximum flow count (%u) has been exceeded\n",
workflow->prefs.max_ndpi_flows);
- exit(-1);
+ return NULL;
} else {
struct ndpi_flow_info *newflow = (struct ndpi_flow_info*)ndpi_malloc(sizeof(struct ndpi_flow_info));
diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am
index b70eae2d8..7858c3371 100644
--- a/fuzz/Makefile.am
+++ b/fuzz/Makefile.am
@@ -15,8 +15,8 @@ fuzz_process_packet_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
fuzz_ndpi_reader_SOURCES = fuzz_ndpi_reader.c
fuzz_ndpi_reader_CFLAGS = -I../example/
-fuzz_ndpi_reader_LDADD = ../src/lib/libndpi.a
-fuzz_ndpi_reader_LDFLAGS = ../example/libndpiReader.a $(PCAP_LIB) $(ADDITIONAL_LIBS) $(LIBS)
+fuzz_ndpi_reader_LDADD = ../example/libndpiReader.a ../src/lib/libndpi.a
+fuzz_ndpi_reader_LDFLAGS = $(PCAP_LIB) $(ADDITIONAL_LIBS) $(LIBS)
if HAS_FUZZLDFLAGS
fuzz_ndpi_reader_CFLAGS += $(LIB_FUZZING_ENGINE)
fuzz_ndpi_reader_LDFLAGS += $(LIB_FUZZING_ENGINE)
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index aecd1ef2c..355e49113 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -6429,8 +6429,6 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
void ndpi_free_flow_data(struct ndpi_flow_struct *flow) {
if(flow) {
- u_int is_quic = flow_is_proto(flow, NDPI_PROTOCOL_QUIC);
-
if(flow->http.url)
ndpi_free(flow->http.url);
@@ -6446,10 +6444,12 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
if(flow->kerberos_buf.pktbuf)
ndpi_free(flow->kerberos_buf.pktbuf);
- if(is_quic
- || flow_is_proto(flow, NDPI_PROTOCOL_TLS)
- || flow_is_proto(flow, NDPI_PROTOCOL_DTLS)
- ) {
+ if (flow_is_proto(flow, NDPI_PROTOCOL_QUIC) ||
+ flow_is_proto(flow, NDPI_PROTOCOL_TLS) ||
+ flow_is_proto(flow, NDPI_PROTOCOL_DTLS) ||
+ flow_is_proto(flow, NDPI_PROTOCOL_MAIL_SMTPS) ||
+ flow_is_proto(flow, NDPI_PROTOCOL_MAIL_POPS) ||
+ flow_is_proto(flow, NDPI_PROTOCOL_MAIL_IMAPS)) {
if(flow->protos.tls_quic_stun.tls_quic.server_names)
ndpi_free(flow->protos.tls_quic_stun.tls_quic.server_names);
@@ -6467,7 +6467,7 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
if(flow->protos.tls_quic_stun.tls_quic.encrypted_sni.esni)
ndpi_free(flow->protos.tls_quic_stun.tls_quic.encrypted_sni.esni);
- }
+ }
if(flow->l4_proto == IPPROTO_TCP) {
if(flow->l4.tcp.tls.message.buffer)