Skip to content

Commit

Permalink
Also don't treat an empty buffer as JSON.
Browse files Browse the repository at this point in the history
That also keeps us from looking at the non-existent first octet of an
empty buffer.

Bug: 16031
Change-Id: I3fcf4201d21dc44ccd8815cb0637c1eae4995560
Reviewed-on: https://code.wireshark.org/review/34439
Petri-Dish: Guy Harris <[email protected]>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <[email protected]>
  • Loading branch information
guyharris committed Sep 3, 2019
1 parent 6b28772 commit fd425b1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wsutil/wsjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ json_validate(const guint8 *buf, const size_t len)
return FALSE;

/*
* Make sure the first octet isn't a NUL; otherwise, the parser will
* immediately stop parsing and not validate anything after that,
* so it'll just think it was handed an empty string.
* 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
* anything after that, so it'll just think it was handed an empty string.
*
* XXX - should we check for NULs anywhere in the buffer?
*/
if (len == 0) {
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: JSON string is empty");
return FALSE;
}
if (buf[0] == '\0') {
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: invalid character inside JSON string");
return FALSE;
Expand Down

0 comments on commit fd425b1

Please sign in to comment.