Merge pull request #469 from vel21ripn/dev

Fix undefined behavior (detected by gcc):
This commit is contained in:
Michele Campus
2017-10-03 16:08:14 +02:00
committed by GitHub
3 changed files with 16 additions and 14 deletions
+3 -3
View File
@@ -215,9 +215,9 @@
#define howmanybits(x, y) (((x)+((y)-1))/(y)) #define howmanybits(x, y) (((x)+((y)-1))/(y))
#define NDPI_SET(p, n) ((p)->fds_bits[(n)/NDPI_BITS] |= (1 << (((u_int32_t)n) % NDPI_BITS))) #define NDPI_SET(p, n) ((p)->fds_bits[(n)/NDPI_BITS] |= (1ul << (((u_int32_t)n) % NDPI_BITS)))
#define NDPI_CLR(p, n) ((p)->fds_bits[(n)/NDPI_BITS] &= ~(1 << (((u_int32_t)n) % NDPI_BITS))) #define NDPI_CLR(p, n) ((p)->fds_bits[(n)/NDPI_BITS] &= ~(1ul << (((u_int32_t)n) % NDPI_BITS)))
#define NDPI_ISSET(p, n) ((p)->fds_bits[(n)/NDPI_BITS] & (1 << (((u_int32_t)n) % NDPI_BITS))) #define NDPI_ISSET(p, n) ((p)->fds_bits[(n)/NDPI_BITS] & (1ul << (((u_int32_t)n) % NDPI_BITS)))
#define NDPI_ZERO(p) memset((char *)(p), 0, sizeof(*(p))) #define NDPI_ZERO(p) memset((char *)(p), 0, sizeof(*(p)))
#define NDPI_ONE(p) memset((char *)(p), 0xFF, sizeof(*(p))) #define NDPI_ONE(p) memset((char *)(p), 0xFF, sizeof(*(p)))
+5 -3
View File
@@ -360,9 +360,11 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len); strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
flow->host_server_name[len] = '\0', flow->server_id = flow->dst; flow->host_server_name[len] = '\0', flow->server_id = flow->dst;
len = ndpi_min(packet->forwarded_line.len, sizeof(flow->protos.http.nat_ip)-1); if(packet->forwarded_line.ptr) {
strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len); len = ndpi_min(packet->forwarded_line.len, sizeof(flow->protos.http.nat_ip)-1);
flow->protos.http.nat_ip[len] = '\0'; strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len);
flow->protos.http.nat_ip[len] = '\0';
}
if(ndpi_struct->http_dont_dissect_response) if(ndpi_struct->http_dont_dissect_response)
parseHttpSubprotocol(ndpi_struct, flow); parseHttpSubprotocol(ndpi_struct, flow);
+8 -8
View File
@@ -74,14 +74,14 @@ ndpi_prefix_tochar (prefix_t * prefix)
} }
int ndpi_comp_with_mask (void *addr, void *dest, u_int mask) { int ndpi_comp_with_mask (void *addr, void *dest, u_int mask) {
if( /* mask/8 == 0 || */ memcmp (addr, dest, mask / 8) == 0) { uint32_t *pa = addr;
int n = mask / 8; uint32_t *pd = dest;
int m = ((-1) << (8 - (mask % 8))); uint32_t m;
for(;mask >= 32; mask -= 32, pa++,pd++)
if(mask % 8 == 0 || (((u_char *)addr)[n] & m) == (((u_char *)dest)[n] & m)) if(*pa != *pd) return 0;
return (1); if(!mask) return 1;
} m = htonl((~0u) << (32-mask));
return (0); return (*pa & m) == (*pd &m);
} }
/* this allows incomplete prefix */ /* this allows incomplete prefix */