Merge pull request #731 from themadprofessor/dev

Stability Fixes
This commit is contained in:
Luca Deri
2019-07-01 20:02:49 +02:00
committed by GitHub
6 changed files with 55 additions and 35 deletions
+4 -4
View File
@@ -768,7 +768,7 @@ extern "C" {
ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_detection_module_size();
u_int ndpi_get_ndpi_detection_module_size(void);
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
/* LRU cache */
@@ -795,9 +795,9 @@ extern "C" {
void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr));
void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str,
ndpi_debug_function_ptr ndpi_debug_printf);
void * ndpi_malloc(size_t size);
void * ndpi_calloc(unsigned long count, size_t size);
void ndpi_free(void *ptr);
//void * ndpi_malloc(size_t size);
//void * ndpi_calloc(unsigned long count, size_t size);
//void ndpi_free(void *ptr);
u_int8_t ndpi_get_api_version();
/* https://github.com/corelight/community-id-spec */
+31 -26
View File
@@ -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;
#ifdef NDPI_DETECTION_SUPPORT_IPV6
flow->packet.iphv6 = NULL;
#endif /* NDPI_DETECTION_SUPPORT_IPV6 */
if (!flow) {
return 1;
}
if(flow)
ndpi_apply_flow_protocol_to_packet(flow, &flow->packet);
else
ndpi_int_reset_packet_protocol(&flow->packet);
/* 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;
#endif /* NDPI_DETECTION_SUPPORT_IPV6 */
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);
+1 -1
View File
@@ -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
+8
View File
@@ -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");
+6 -3
View File
@@ -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;
+5 -1
View File
@@ -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;
}