From 3a1c49a6603f643289f0136775e7b7a27c73fa6d Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Sun, 29 May 2022 19:14:57 +0200 Subject: [PATCH] Fix dissection of IPv4 header See: https://github.com/ntop/nDPI/runs/6643914510?check_suite_focus=true Convert al the `MIN(a,b)` calls to `ndpi_min(a,b)` --- src/include/ndpi_win32.h | 4 ---- src/lib/ndpi_main.c | 2 +- src/lib/protocols/quic.c | 2 +- src/lib/protocols/tls.c | 4 ++-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/include/ndpi_win32.h b/src/include/ndpi_win32.h index 7885b13efcd..74a38b5f7ee 100644 --- a/src/include/ndpi_win32.h +++ b/src/include/ndpi_win32.h @@ -49,10 +49,6 @@ #define IPVERSION 4 /* on *nix it is defined in netinet/ip.h */ -#ifndef MIN -#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) -#endif - #if defined(__MINGW32__) || defined(__MINGW64__) #undef gettimeofday #define gettimeofday mingw_gettimeofday diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 5f5fd593d76..52c2b8f85ef 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -4664,7 +4664,7 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru /* 0: fragmented; 1: not fragmented */ if(iph != NULL && ndpi_iph_is_valid_and_not_fragmented(iph, l3_len)) { - u_int16_t len = ntohs(iph->tot_len); + u_int16_t len = ndpi_min(ntohs(iph->tot_len), l3_len); u_int16_t hlen = (iph->ihl * 4); l4ptr = (((const u_int8_t *) iph) + iph->ihl * 4); diff --git a/src/lib/protocols/quic.c b/src/lib/protocols/quic.c index a8b2827f264..d3512cd9b79 100644 --- a/src/lib/protocols/quic.c +++ b/src/lib/protocols/quic.c @@ -375,7 +375,7 @@ static gcry_error_t hkdf_expand(int hashalgo, const uint8_t *prk, uint32_t prk_l gcry_md_write(h, &c, sizeof(c)); /* constant 0x01..N */ memcpy(lastoutput, gcry_md_read(h, hashalgo), hash_len); - memcpy(out + offset, lastoutput, MIN(hash_len, out_len - offset)); + memcpy(out + offset, lastoutput, ndpi_min(hash_len, out_len - offset)); } gcry_md_close(h); diff --git a/src/lib/protocols/tls.c b/src/lib/protocols/tls.c index 608e4ffb31c..a878e21ae4d 100644 --- a/src/lib/protocols/tls.c +++ b/src/lib/protocols/tls.c @@ -2200,10 +2200,10 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct, } else { u_int16_t seq_len = ntohs(*((u_int16_t*)&packet->payload[s_offset])); s_offset += 2; - final_offset = MIN(total_len, s_offset + seq_len); + final_offset = ndpi_min(total_len, s_offset + seq_len); } } else { - final_offset = MIN(total_len, s_offset + extension_len); + final_offset = ndpi_min(total_len, s_offset + extension_len); } while(s_offset < final_offset) {