diff options
author | Luca Deri <lucaderi@users.noreply.github.com> | 2016-04-12 21:22:38 +0200 |
---|---|---|
committer | Luca Deri <lucaderi@users.noreply.github.com> | 2016-04-12 21:22:38 +0200 |
commit | 885cc3864eccaa0eaadff7233f5a6a94c4239e24 (patch) | |
tree | ec73052cd681ec4b63bfbe5421fba779ed25e1c4 | |
parent | 5a37ee99764b7d262676b0ca052075c9c559c01d (diff) | |
parent | 624f61193cd1d9d203a5d05f9accfaed19ccd53a (diff) |
Merge pull request #172 from theirix/reader-asan
Allocate exact-size buffer with address sanitizer
-rw-r--r-- | example/ndpiReader.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 52fac6a65..a7b4bf418 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -51,6 +51,17 @@ #include <json.h> #endif +/* Check for buffer allocation errors if address-sanitizer is enabled */ +#if defined(__has_feature) +#if __has_feature(address_sanitizer) +#define NDPI_STRICT_BUFFER_CHECK 1 +#endif +#endif +/* Check for GCC */ +#ifdef __SANITIZE_ADDRESS__ +#define NDPI_STRICT_BUFFER_CHECK 1 +#endif + #define MAX_NUM_READER_THREADS 16 #define IDLE_SCAN_PERIOD 10 /* msec (use detection_tick_resolution = 1000) */ #define MAX_IDLE_TIME 30000 @@ -1940,11 +1951,28 @@ static void pcap_packet_callback(u_char *args, thread_id, (unsigned long)ndpi_thread_info[thread_id].stats.raw_packet_count); } +#ifdef NDPI_STRICT_BUFFER_CHECK +static void pcap_packet_callback_checked(u_char *args, + const struct pcap_pkthdr *header, + const u_char *packet) { + uint8_t *packet_checked = malloc(header->caplen); + memcpy(packet_checked, packet, header->caplen); + pcap_packet_callback(args, header, packet_checked); + free(packet_checked); +} +#else +static void pcap_packet_callback_checked(u_char *args, + const struct pcap_pkthdr *header, + const u_char *packet) { + pcap_packet_callback(args, header, packet); +} +#endif + /* ******************************************************************** */ static void runPcapLoop(u_int16_t thread_id) { if((!shutdown_app) && (ndpi_thread_info[thread_id]._pcap_handle != NULL)) - pcap_loop(ndpi_thread_info[thread_id]._pcap_handle, -1, &pcap_packet_callback, (u_char*)&thread_id); + pcap_loop(ndpi_thread_info[thread_id]._pcap_handle, -1, &pcap_packet_callback_checked, (u_char*)&thread_id); } /* ******************************************************************** */ |