aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_main.c
diff options
context:
space:
mode:
authorLuca Deri <lucaderi@users.noreply.github.com>2019-07-01 20:02:49 +0200
committerGitHub <noreply@github.com>2019-07-01 20:02:49 +0200
commit7cb7a12f968d863f2b8ce5f1eb3d9d52fefa3101 (patch)
tree5cd9d1776738bfb00f667af9456665ebc8293959 /src/lib/ndpi_main.c
parent8fdef484f6c1e11cca0468032092f058cf803a14 (diff)
parent5ce5bae99dbb999921e50945495a5160c9de2953 (diff)
Merge pull request #731 from themadprofessor/dev
Stability Fixes
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r--src/lib/ndpi_main.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index aa2f2273a..3cf0f3d1e 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -3473,24 +3473,23 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
u_int8_t l4protocol;
u_int8_t l4_result;
- if(flow) {
- /* reset payload_packet_len, will be set if ipv4 tcp or udp */
- flow->packet.payload_packet_len = 0;
- flow->packet.l4_packet_len = 0;
- flow->packet.l3_packet_len = packetlen;
-
- flow->packet.tcp = NULL;
- flow->packet.udp = NULL;
- flow->packet.generic_l4_ptr = NULL;
+ if (!flow) {
+ return 1;
+ }
+
+ /* reset payload_packet_len, will be set if ipv4 tcp or udp */
+ flow->packet.payload_packet_len = 0;
+ flow->packet.l4_packet_len = 0;
+ flow->packet.l3_packet_len = packetlen;
+
+ flow->packet.tcp = NULL;
+ flow->packet.udp = NULL;
+ flow->packet.generic_l4_ptr = NULL;
#ifdef NDPI_DETECTION_SUPPORT_IPV6
- flow->packet.iphv6 = NULL;
+ flow->packet.iphv6 = NULL;
#endif /* NDPI_DETECTION_SUPPORT_IPV6 */
- }
- if(flow)
- ndpi_apply_flow_protocol_to_packet(flow, &flow->packet);
- else
- ndpi_int_reset_packet_protocol(&flow->packet);
+ ndpi_apply_flow_protocol_to_packet(flow, &flow->packet);
l3len = flow->packet.l3_packet_len;
@@ -3556,7 +3555,7 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
/* check for new tcp syn packets, here
* idea: reset detection state if a connection is unknown
*/
- if(flow && flow->packet.tcp->syn != 0
+ if(flow->packet.tcp->syn != 0
&& flow->packet.tcp->ack == 0
&& flow->init_finished != 0
&& flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
@@ -3604,6 +3603,10 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
const struct ndpi_tcphdr *tcph = packet->tcp;
const struct ndpi_udphdr *udph = flow->packet.udp;
+ if (!flow) {
+ return;
+ }
+
packet->tcp_retransmission = 0, packet->packet_direction = 0;
if(ndpi_struct->direction_detect_disable) {
@@ -3620,8 +3623,6 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
}
packet->packet_lines_parsed_complete = 0;
- if(flow == NULL)
- return;
if(flow->init_finished == 0) {
flow->init_finished = 1;
@@ -3716,6 +3717,11 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
void check_ndpi_other_flow_func(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE *ndpi_selection_packet) {
+
+ if (!flow) {
+ return;
+ }
+
void *func = NULL;
u_int32_t a;
u_int16_t proto_index = ndpi_struct->proto_defaults[flow->guessed_protocol_id].protoIdx;
@@ -3741,10 +3747,9 @@ void check_ndpi_other_flow_func(struct ndpi_detection_module_struct *ndpi_struct
if((func != ndpi_struct->callback_buffer_non_tcp_udp[a].func)
&& (ndpi_struct->callback_buffer_non_tcp_udp[a].ndpi_selection_bitmask & *ndpi_selection_packet) ==
ndpi_struct->callback_buffer_non_tcp_udp[a].ndpi_selection_bitmask
- && (flow == NULL
- ||
+ &&
NDPI_BITMASK_COMPARE(flow->excluded_protocol_bitmask,
- ndpi_struct->callback_buffer_non_tcp_udp[a].excluded_protocol_bitmask) == 0)
+ ndpi_struct->callback_buffer_non_tcp_udp[a].excluded_protocol_bitmask) == 0
&& NDPI_BITMASK_COMPARE(ndpi_struct->callback_buffer_non_tcp_udp[a].detection_bitmask,
detection_bitmask) != 0) {
@@ -5683,8 +5688,8 @@ ndpi_protocol_category_t ndpi_get_proto_category(struct ndpi_detection_module_st
char* ndpi_get_proto_name(struct ndpi_detection_module_struct *ndpi_mod, u_int16_t proto_id) {
if((proto_id >= ndpi_mod->ndpi_num_supported_protocols)
- || ((proto_id < (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS))
- && (ndpi_mod->proto_defaults[proto_id].protoName == NULL)))
+ || (proto_id < (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS))
+ || (ndpi_mod->proto_defaults[proto_id].protoName == NULL))
proto_id = NDPI_PROTOCOL_UNKNOWN;
return(ndpi_mod->proto_defaults[proto_id].protoName);
@@ -5695,8 +5700,8 @@ char* ndpi_get_proto_name(struct ndpi_detection_module_struct *ndpi_mod, u_int16
ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *ndpi_mod,
u_int16_t proto_id) {
if((proto_id >= ndpi_mod->ndpi_num_supported_protocols)
- || ((proto_id < (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS))
- && (ndpi_mod->proto_defaults[proto_id].protoName == NULL)))
+ || (proto_id < (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS))
+ || (ndpi_mod->proto_defaults[proto_id].protoName == NULL))
proto_id = NDPI_PROTOCOL_UNKNOWN;
return(ndpi_mod->proto_defaults[proto_id].protoBreed);