From ca68beda85b6b2fb8f96d9465997c0a371e3d152 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 23 Jun 2020 18:33:01 +0200 Subject: [PATCH] Fixed missing length check in fbzero. Signed-off-by: Toni Uhlig --- src/lib/protocols/fbzero.c | 5 ++++- tests/pcap/fbzero-missing-lengthcheck.pcap | Bin 0 -> 215 bytes tests/result/fbzero-missing-lengthcheck.pcap.out | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/pcap/fbzero-missing-lengthcheck.pcap create mode 100644 tests/result/fbzero-missing-lengthcheck.pcap.out diff --git a/src/lib/protocols/fbzero.c b/src/lib/protocols/fbzero.c index 6c818e3c7..936d99e84 100644 --- a/src/lib/protocols/fbzero.c +++ b/src/lib/protocols/fbzero.c @@ -85,9 +85,12 @@ void ndpi_search_fbzero(struct ndpi_detection_module_struct *ndpi_struct, char *value = (char*)&packet->payload[data_offset + data_prev_offset]; u_int tag_len = t->tag_offset_len-data_prev_offset, max_len; ndpi_protocol_match_result ret_match; - + max_len = ndpi_min(tag_len, sizeof(flow->host_server_name)-1); + if (data_offset + data_prev_offset + max_len >= packet->payload_packet_len) { + return; + } strncpy((char*)flow->host_server_name, value, max_len); flow->host_server_name[max_len] = '\0'; diff --git a/tests/pcap/fbzero-missing-lengthcheck.pcap b/tests/pcap/fbzero-missing-lengthcheck.pcap new file mode 100644 index 0000000000000000000000000000000000000000..32855cebc1074e4ee8f73ed4f40f11a9e6270870 GIT binary patch literal 215 zcmca|c+)~A1{MYcU}0bca?Y{7kIeRGVOS4jgRsfw5T>@HPYzxDtRTq2;L5vKQw@~v-W+|8nI^Q0&AV0nWC!>WCc7#J8CIk*@~%M`jcDU})qhJ+bh z0vhG);p5K*q=WrD8H9kepTD285s-Ftb#yTUi936`xB=-9PhVFrkho8PpC6D82z3h1 m1JYrxLBT~p+S@fExC}@K1$#zS0qOLj#DWaHw8Z4pq 157.240.13.14:443 [proto: 91.119/TLS.Facebook][cat: SocialNetwork/6][1 pkts/175 bytes -> 0 pkts/0 bytes][Goodput ratio: 62/0][< 1 sec][Plen Bins: 0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]