fix segmentation fault caused by missing spanning tree check - add control for threads return values
This commit is contained in:
+24
-6
@@ -1331,7 +1331,7 @@ static void pcap_packet_callback_checked(u_char *args,
|
|||||||
u_int16_t thread_id = *((u_int16_t*)args);
|
u_int16_t thread_id = *((u_int16_t*)args);
|
||||||
|
|
||||||
/* allocate an exact size buffer to check overflows */
|
/* allocate an exact size buffer to check overflows */
|
||||||
uint8_t *packet_checked = malloc(header->caplen);
|
uint8_t *packet_checked = malloc(header->caplen); /* HEAP OVERFLOW !!! */
|
||||||
|
|
||||||
memcpy(packet_checked, packet, header->caplen);
|
memcpy(packet_checked, packet, header->caplen);
|
||||||
p = ndpi_workflow_process_packet(ndpi_thread_info[thread_id].workflow, header, packet_checked);
|
p = ndpi_workflow_process_packet(ndpi_thread_info[thread_id].workflow, header, packet_checked);
|
||||||
@@ -1478,13 +1478,31 @@ void test_lib() {
|
|||||||
|
|
||||||
gettimeofday(&begin, NULL);
|
gettimeofday(&begin, NULL);
|
||||||
|
|
||||||
/* Running processing threads */
|
int status;
|
||||||
for(thread_id = 0; thread_id < num_threads; thread_id++)
|
void * thd_res;
|
||||||
pthread_create(&ndpi_thread_info[thread_id].pthread, NULL, processing_thread, (void *) thread_id);
|
|
||||||
|
|
||||||
|
/* Running processing threads */
|
||||||
|
for(thread_id = 0; thread_id < num_threads; thread_id++) {
|
||||||
|
status = pthread_create(&ndpi_thread_info[thread_id].pthread, NULL, processing_thread, (void *) thread_id);
|
||||||
|
/* check pthreade_create return value */
|
||||||
|
if(status != 0) {
|
||||||
|
fprintf(stderr, "error on create %ld thread\n", thread_id);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Waiting for completion */
|
/* Waiting for completion */
|
||||||
for(thread_id = 0; thread_id < num_threads; thread_id++)
|
for(thread_id = 0; thread_id < num_threads; thread_id++) {
|
||||||
pthread_join(ndpi_thread_info[thread_id].pthread, NULL);
|
status = pthread_join(ndpi_thread_info[thread_id].pthread, thd_res);
|
||||||
|
/* check pthreade_join return value */
|
||||||
|
if(status != 0) {
|
||||||
|
fprintf(stderr, "error on join %ld thread\n", thread_id);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
if(thd_res != NULL) {
|
||||||
|
fprintf(stderr, "error on returned value of %ld joined thread\n", thread_id);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
tot_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec);
|
tot_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec);
|
||||||
|
|||||||
+10
-3
@@ -48,6 +48,7 @@
|
|||||||
#define MPLS_MULTI 0x8848
|
#define MPLS_MULTI 0x8848
|
||||||
#define PPPoE 0x8864
|
#define PPPoE 0x8864
|
||||||
#define SNAP 0xaa
|
#define SNAP 0xaa
|
||||||
|
#define BSTP 0x42 /* Bridge Spanning Tree Protocol */
|
||||||
|
|
||||||
/* mask for FCF */
|
/* mask for FCF */
|
||||||
#define WIFI_DATA 0x2 /* 0000 0010 */
|
#define WIFI_DATA 0x2 /* 0000 0010 */
|
||||||
@@ -286,8 +287,10 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
|
|||||||
tcp_len = ndpi_min(4*(*tcph)->doff, l4_packet_len);
|
tcp_len = ndpi_min(4*(*tcph)->doff, l4_packet_len);
|
||||||
*payload = &l4[tcp_len];
|
*payload = &l4[tcp_len];
|
||||||
*payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff);
|
*payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff);
|
||||||
} else if(iph->protocol == IPPROTO_UDP && l4_packet_len >= 8) {
|
|
||||||
// udp
|
// udp
|
||||||
|
} else if(iph->protocol == IPPROTO_UDP && l4_packet_len >= 8) {
|
||||||
|
|
||||||
workflow->stats.udp_count++;
|
workflow->stats.udp_count++;
|
||||||
|
|
||||||
*udph = (struct ndpi_udphdr *)l4;
|
*udph = (struct ndpi_udphdr *)l4;
|
||||||
@@ -670,12 +673,16 @@ struct ndpi_proto ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
|
|||||||
type = check;
|
type = check;
|
||||||
|
|
||||||
if(pyld_eth_len != 0) {
|
if(pyld_eth_len != 0) {
|
||||||
|
llc = (struct ndpi_llc_header *)(&packet[ip_offset]);
|
||||||
/* check for LLC layer with SNAP extension */
|
/* check for LLC layer with SNAP extension */
|
||||||
if(packet[ip_offset] == SNAP) {
|
if(llc->dsap == SNAP || llc->ssap == SNAP) {
|
||||||
llc = (struct ndpi_llc_header *)(&packet[ip_offset]);
|
#define SNAP_EXT
|
||||||
type = llc->snap.proto_ID;
|
type = llc->snap.proto_ID;
|
||||||
ip_offset += + 8;
|
ip_offset += + 8;
|
||||||
}
|
}
|
||||||
|
else if(llc->dsap == BSTP || llc->ssap == BSTP) {
|
||||||
|
goto v4_warning;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user