Proxy: fix heuristic dissector
authorPascal Quantin <pascal.quantin@gmail.com>
Mon, 27 Aug 2018 07:31:15 +0000 (09:31 +0200)
committerPascal Quantin <pascal.quantin@gmail.com>
Mon, 27 Aug 2018 08:46:03 +0000 (08:46 +0000)
Ensure that at least 12 bytes were captured before trying to check the magic.
Otherwise it can trigger an exception and prevent other heuristic dissectors
from being called.

Change-Id: Ib90febc208a69ae4e10c5c971e7cddfa7157c8a4
Reviewed-on: https://code.wireshark.org/review/29298
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
epan/dissectors/packet-proxy.c

index 8e24a4aa354f37f7f89081b582f0da5e37604194..633e5df870c4e3f1968971c6b1791fd30fa08ec4 100644 (file)
@@ -258,8 +258,9 @@ dissect_proxy_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 static gboolean
 dissect_proxy_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
 {
-    guint length = tvb_reported_length(tvb);
-    if (length >= 16 && tvb_memeql(tvb, 0, proxy_v2_magic, sizeof(proxy_v2_magic)) == 0) {
+    if (tvb_reported_length(tvb) >= 16 &&
+        tvb_captured_length(tvb) >= sizeof(proxy_v2_magic) &&
+        tvb_memeql(tvb, 0, proxy_v2_magic, sizeof(proxy_v2_magic)) == 0) {
         // TODO maybe check for "(hdr.v2.ver_cmd & 0xF0) == 0x20" as done in "9. Sample code" from
         // https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt?
         dissect_proxy_v2(tvb, pinfo, tree, data);