diff options
author | Pascal Quantin <pascal@wireshark.org> | 2019-09-06 09:57:54 +0200 |
---|---|---|
committer | Jaap Keuter <jaap.keuter@xs4all.nl> | 2019-09-06 08:42:24 +0000 |
commit | aa3c5087d9c0a9f37edd9982046843eab2baf590 (patch) | |
tree | f19aee45443f1f42154657899b5abc4eecf203a6 /wsutil | |
parent | 31abf81250ea860e82b5716167a92cb3cfd197bf (diff) |
wsjson.c: do not leak memory when checking input buffer in json_validate()
Bug: 16039
Change-Id: Id3c22fbee87b5a8f5d2e4bc488ad902098fa5f05
Reviewed-on: https://code.wireshark.org/review/34459
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Diffstat (limited to 'wsutil')
-rw-r--r-- | wsutil/wsjson.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/wsutil/wsjson.c b/wsutil/wsjson.c index 47f8220a6c..567fa2dd5c 100644 --- a/wsutil/wsjson.c +++ b/wsutil/wsjson.c @@ -31,11 +31,6 @@ json_validate(const guint8 *buf, const size_t len) jsmn_parser p; int rcode; - t = g_new0(jsmntok_t, max_tokens); - - if (!t) - return FALSE; - /* * Make sure the buffer isn't empty and the first octet isn't a NUL; * otherwise, the parser will immediately stop parsing and not validate @@ -52,6 +47,11 @@ json_validate(const guint8 *buf, const size_t len) return FALSE; } + t = g_new0(jsmntok_t, max_tokens); + + if (!t) + return FALSE; + jsmn_init(&p); rcode = jsmn_parse(&p, buf, len, t, max_tokens); if (rcode < 0) { |