aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
5 files changed, 50 insertions, 30 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);
diff --git a/src/lib/protocols/btlib.c b/src/lib/protocols/btlib.c
index 309a10717..71b4dff9a 100644
--- a/src/lib/protocols/btlib.c
+++ b/src/lib/protocols/btlib.c
@@ -423,7 +423,7 @@ const u_int8_t *bt_decode(const u_int8_t *b, size_t *l, int *ret, bt_parse_data_
int64_t d = 0;
u_int8_t c;
- if(*l == 0) return NULL;
+ if(!l || *l == 0) return NULL;
if(cbd->level > BDEC_MAXDEPT) goto bad_data;
c = *b++; (*l)--;
if(c == 'i') { // integer
diff --git a/src/lib/protocols/eaq.c b/src/lib/protocols/eaq.c
index 8768cac6f..e86b83181 100644
--- a/src/lib/protocols/eaq.c
+++ b/src/lib/protocols/eaq.c
@@ -41,7 +41,15 @@ static void ndpi_int_eaq_add_connection(struct ndpi_detection_module_struct *ndp
void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
+ if (!flow) {
+ return;
+ }
+
struct ndpi_packet_struct *packet = &flow->packet;
+ if (!packet) {
+ return;
+ }
+
u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG_DBG(ndpi_struct, "search eaq\n");
diff --git a/src/lib/third_party/src/ht_hash.c b/src/lib/third_party/src/ht_hash.c
index 4eaac9bcb..838fc2c6d 100644
--- a/src/lib/third_party/src/ht_hash.c
+++ b/src/lib/third_party/src/ht_hash.c
@@ -23,9 +23,10 @@ hashtable_t *ht_create(int size) {
return NULL;
/* Allocate pointers to the head nodes. */
- if((hashtable->table = ndpi_malloc(sizeof(entry_t *) * size)) == NULL)
+ if((hashtable->table = ndpi_malloc(sizeof(entry_t *) * size)) == NULL) {
+ free(hashtable);
return NULL;
- else {
+ } else {
for(i = 0; i < size; i++)
hashtable->table[i] = NULL;
}
@@ -61,8 +62,10 @@ entry_t *ht_newpair(char *key, u_int16_t value) {
if((newpair = ndpi_malloc(sizeof(entry_t))) == NULL)
return NULL;
- if((newpair->key = ndpi_strdup(key)) == NULL)
+ if((newpair->key = ndpi_strdup(key)) == NULL) {
+ free(newpair);
return NULL;
+ }
newpair->value = value, newpair->next = NULL;
diff --git a/src/lib/third_party/src/libcache.c b/src/lib/third_party/src/libcache.c
index 4479ff54d..597684ccc 100644
--- a/src/lib/third_party/src/libcache.c
+++ b/src/lib/third_party/src/libcache.c
@@ -196,7 +196,11 @@ cache_result cache_add(cache_t cache, void *item, uint32_t item_size) {
}
if(hash_entry_map_prev) {
- hash_entry_map_prev->next = hash_entry_map->next;
+ if (hash_entry_map) {
+ hash_entry_map_prev->next = hash_entry_map->next;
+ } else {
+ hash_entry_map_prev->next = NULL;
+ }
} else {
cache->map[hash] = hash_entry_map->next;
}