aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <lucaderi@users.noreply.github.com>2018-09-13 01:11:01 +0300
committerGitHub <noreply@github.com>2018-09-13 01:11:01 +0300
commit24110acafcc143bfdc66ef868ef26bd03adead75 (patch)
tree11f4b91222325a4a8bec4a2e155af41c53bef54a
parentf6f242b8997f657f1eed85f139d1840930a1e328 (diff)
parentc0ed50d5b002838ded46ee22852404998389f9b7 (diff)
Merge pull request #606 from eglooca/pr-fix-parse-packet-line-info
Prevent missing text lines and invalid reads past end-of-buffer.
-rw-r--r--src/lib/ndpi_main.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 722fdb68f..b904bbefc 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -4641,7 +4641,11 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
packet->line[packet->parsed_lines].ptr = packet->payload;
packet->line[packet->parsed_lines].len = 0;
- for(a = 0; a < packet->payload_packet_len-2; a++) {
+ for(a = 0; a < packet->payload_packet_len; a++) {
+
+ if((a + 1) == packet->payload_packet_len)
+ return; /* Return if only one byte remains (prevent invalid reads past end-of-buffer) */
+
if(get_u_int16_t(packet->payload, a) == ntohs(0x0d0a)) { /* If end of line char sequence CR+NL "\r\n", process line */
packet->line[packet->parsed_lines].len = (u_int16_t)(((unsigned long) &packet->payload[a]) - ((unsigned long) packet->line[packet->parsed_lines].ptr));
@@ -4821,9 +4825,6 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
packet->line[packet->parsed_lines].ptr = &packet->payload[a + 2];
packet->line[packet->parsed_lines].len = 0;
- if((a + 2) >= packet->payload_packet_len)
- return;
-
a++; /* next char in the payload */
}
}