aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-09-02 20:02:59 -0700
committerGuy Harris <guy@alum.mit.edu>2019-09-03 03:21:38 +0000
commitfd425b195cff4b2138ed36e0cd30304348eb034a (patch)
tree9dffcf0b80b4fe6f8b0ced08c40ea73d84aec07b
parent6b28772660ce673e1c9a30dbcea6a06bdcd2a3c7 (diff)
Also don't treat an empty buffer as JSON.
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 <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--wsutil/wsjson.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/wsutil/wsjson.c b/wsutil/wsjson.c
index 087c510894..47f8220a6c 100644
--- a/wsutil/wsjson.c
+++ b/wsutil/wsjson.c
@@ -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;