forked from osmocom/wireshark
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>
This commit is contained in:
parent
31abf81250
commit
aa3c5087d9
|
@ -31,11 +31,6 @@ json_validate(const guint8 *buf, const size_t len)
|
||||||
jsmn_parser p;
|
jsmn_parser p;
|
||||||
int rcode;
|
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;
|
* 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
|
* 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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t = g_new0(jsmntok_t, max_tokens);
|
||||||
|
|
||||||
|
if (!t)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
jsmn_init(&p);
|
jsmn_init(&p);
|
||||||
rcode = jsmn_parse(&p, buf, len, t, max_tokens);
|
rcode = jsmn_parse(&p, buf, len, t, max_tokens);
|
||||||
if (rcode < 0) {
|
if (rcode < 0) {
|
||||||
|
|
Loading…
Reference in New Issue