Added check for heap buffer overflow read

This commit is contained in:
Luca Deri
2020-05-29 21:43:06 +02:00
parent 4ceff1dc77
commit 61066fb106
+7 -1
View File
@@ -4807,29 +4807,34 @@ u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t *str, u_int16_t max_chars_to_re
u_int16_t read = 0; u_int16_t read = 0;
u_int16_t oldread; u_int16_t oldread;
u_int32_t c; u_int32_t c;
/* ip address must be X.X.X.X with each X between 0 and 255 */ /* ip address must be X.X.X.X with each X between 0 and 255 */
oldread = read; oldread = read;
c = ndpi_bytestream_to_number(str, max_chars_to_read, &read); c = ndpi_bytestream_to_number(str, max_chars_to_read, &read);
if(c > 255 || oldread == read || max_chars_to_read == read || str[read] != '.') if(c > 255 || oldread == read || max_chars_to_read == read || str[read] != '.')
return(0); return(0);
read++; read++;
val = c << 24; val = c << 24;
oldread = read; oldread = read;
c = ndpi_bytestream_to_number(&str[read], max_chars_to_read - read, &read); c = ndpi_bytestream_to_number(&str[read], max_chars_to_read - read, &read);
if(c > 255 || oldread == read || max_chars_to_read == read || str[read] != '.') if(c > 255 || oldread == read || max_chars_to_read == read || str[read] != '.')
return(0); return(0);
read++; read++;
val = val + (c << 16); val = val + (c << 16);
oldread = read; oldread = read;
c = ndpi_bytestream_to_number(&str[read], max_chars_to_read - read, &read); c = ndpi_bytestream_to_number(&str[read], max_chars_to_read - read, &read);
if(c > 255 || oldread == read || max_chars_to_read == read || str[read] != '.') if(c > 255 || oldread == read || max_chars_to_read == read || str[read] != '.')
return(0); return(0);
read++; read++;
val = val + (c << 8); val = val + (c << 8);
oldread = read; oldread = read;
c = ndpi_bytestream_to_number(&str[read], max_chars_to_read - read, &read); c = ndpi_bytestream_to_number(&str[read], max_chars_to_read - read, &read);
if(c > 255 || oldread == read || max_chars_to_read == read) if(c > 255 || oldread == read || max_chars_to_read == read)
return(0); return(0);
val = val + c; val = val + c;
*bytes_read = *bytes_read + read; *bytes_read = *bytes_read + read;
@@ -4869,9 +4874,10 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_str,
int diff; /* No unsigned ! */ int diff; /* No unsigned ! */
u_int32_t a1 = a + 4; u_int32_t a1 = a + 4;
diff = ndpi_min(packet->payload_packet_len-a1, sizeof(flow->initial_binary_bytes)); diff = packet->payload_packet_len - a1;
if(diff > 0) { if(diff > 0) {
diff = ndpi_min(diff, sizeof(flow->initial_binary_bytes));
memcpy(&flow->initial_binary_bytes, &packet->payload[a1], diff); memcpy(&flow->initial_binary_bytes, &packet->payload[a1], diff);
flow->initial_binary_bytes_len = diff; flow->initial_binary_bytes_len = diff;
} }