Fix some memory leakes in reassembler code (#1127)

This commit is contained in:
Ivan Nardi
2021-02-04 19:29:27 +01:00
committed by GitHub
parent 7255dbe4b7
commit 2a65321884
+17 -41
View File
@@ -3764,6 +3764,19 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
u_int8_t backup; u_int8_t backup;
u_int16_t backup1, backup2; u_int16_t backup1, backup2;
backup = flow->num_processed_pkts;
backup1 = flow->guessed_protocol_id;
backup2 = flow->guessed_host_protocol_id;
ndpi_free_flow_data(flow);
memset(flow, 0, sizeof(*(flow)));
/* Restore pointers */
flow->num_processed_pkts = backup;
flow->guessed_protocol_id = backup1;
flow->guessed_host_protocol_id = backup2;
flow->packet.tcp = (struct ndpi_tcphdr *) l4ptr;
flow->l4_proto = IPPROTO_TCP;
#ifdef FRAG_MAN #ifdef FRAG_MAN
/* initialize the buffer to manage segments for a new http/dns connection */ /* initialize the buffer to manage segments for a new http/dns connection */
flow->tcp_segments_management=1; flow->tcp_segments_management=1;
@@ -3773,47 +3786,6 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
} }
#endif // FRAG_MAN #endif // FRAG_MAN
if(flow->http.url) {
ndpi_free(flow->http.url);
flow->http.url = NULL;
}
if(flow->http.content_type) {
ndpi_free(flow->http.content_type);
flow->http.content_type = NULL;
}
if(flow->http.request_content_type) {
ndpi_free(flow->http.request_content_type);
flow->http.request_content_type = NULL;
}
if(flow->http.user_agent) {
ndpi_free(flow->http.user_agent);
flow->http.user_agent = NULL;
}
if(flow->kerberos_buf.pktbuf) {
ndpi_free(flow->kerberos_buf.pktbuf);
flow->kerberos_buf.pktbuf = NULL;
}
if(flow->l4.tcp.tls.message.buffer) {
ndpi_free(flow->l4.tcp.tls.message.buffer);
flow->l4.tcp.tls.message.buffer = NULL;
flow->l4.tcp.tls.message.buffer_len = flow->l4.tcp.tls.message.buffer_used = 0;
}
backup = flow->num_processed_pkts;
backup1 = flow->guessed_protocol_id;
backup2 = flow->guessed_host_protocol_id;
memset(flow, 0, sizeof(*(flow)));
/* Restore pointers */
flow->num_processed_pkts = backup;
flow->guessed_protocol_id = backup1;
flow->guessed_host_protocol_id = backup2;
flow->packet.tcp = (struct ndpi_tcphdr *) l4ptr;
NDPI_LOG_DBG(ndpi_str, "tcp syn packet for unknown protocol, reset detection state\n"); NDPI_LOG_DBG(ndpi_str, "tcp syn packet for unknown protocol, reset detection state\n");
} }
@@ -6495,6 +6467,10 @@ void ndpi_free_flow_data(struct ndpi_flow_struct *flow) {
if(flow->l4_proto == IPPROTO_TCP) { if(flow->l4_proto == IPPROTO_TCP) {
if(flow->l4.tcp.tls.message.buffer) if(flow->l4.tcp.tls.message.buffer)
ndpi_free(flow->l4.tcp.tls.message.buffer); ndpi_free(flow->l4.tcp.tls.message.buffer);
#ifdef FRAG_MAN
free_fragment(&flow->tcp_segments_list[0]);
free_fragment(&flow->tcp_segments_list[1]);
#endif
} }
} }
} }