From 1af7b979276bbc17f4c76e13fc22606b33eb2bac Mon Sep 17 00:00:00 2001 From: Dario Lombardo Date: Mon, 19 Jan 2015 23:12:25 +0100 Subject: [PATCH] Bug fix in json dissector that made the heuristic fail. Change-Id: Iff53cfd8fd9d760b04c638c87f8a44587b268cd7 Reviewed-on: https://code.wireshark.org/review/6674 Reviewed-by: Pascal Quantin Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/packet-json.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/epan/dissectors/packet-json.c b/epan/dissectors/packet-json.c index 9a2c5899d1..64cc5ed9ca 100644 --- a/epan/dissectors/packet-json.c +++ b/epan/dissectors/packet-json.c @@ -572,15 +572,17 @@ static void init_json_parser(void) { static gboolean dissect_json_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + /* We expect no more than 1024 tokens */ + const guint max_tokens = 1024; guint len = tvb_captured_length(tvb); guint8* buf = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, len, ENC_ASCII); jsmn_parser p; - /* We expect no more than 1024 tokens */ - jsmntok_t* t = (jsmntok_t*)wmem_alloc_array(wmem_packet_scope(), jsmntok_t, 1024); + + jsmntok_t* t = (jsmntok_t*)wmem_alloc_array(wmem_packet_scope(), jsmntok_t, max_tokens); jsmn_init(&p); - if (jsmn_parse(&p, buf, len, t, sizeof(t)/sizeof(t[0])) < 0) { + if (jsmn_parse(&p, buf, len, t, max_tokens) < 0) { return FALSE; } return (dissect_json(tvb, pinfo, tree, data) != 0);