Skip to contentSkip to conversation

json-parser: Fix segfault on malformed input

PATCH Applied Kevin Wolf 2 participants 2 messages Feb 24, 2010 – Mar 6, 2010

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 json-parser: Fix segfault on malformed input

If the parser fails to parse the key in parse_pair, it will access a NULL pointer. A simple way to trigger this is sending {foo} via QMP. This patch turns the segfault into a syntax error reply.

---
 json-parser.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
json-parser.c +1 -1
index f3debcb..579928f 100644
@@ -264,7 +264,7 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict, QList **tokens, va_l
 
     peek = qlist_peek(working);
     key = parse_value(ctxt, &working, ap);
-    if (qobject_type(key) != QTYPE_QSTRING) {
+    if (!key || qobject_type(key) != QTYPE_QSTRING) {
         parse_error(ctxt, peek, "key is not a string in object");
         goto out;
     }
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 5 lines · Kevin Wolf

If the parser fails to parse the key in parse_pair, it will access a NULL pointer. A simple way to trigger this is sending {foo} via QMP. This patch turns the segfault into a syntax error reply.

Thanks, applied.

Quoted 23 lines
---
 json-parser.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
json-parser.c +1 -1
index f3debcb..579928f 100644
@@ -264,7 +264,7 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict, QList **tokens, va_l
 
     peek = qlist_peek(working);
     key = parse_value(ctxt, &working, ap);
-    if (qobject_type(key) != QTYPE_QSTRING) {
+    if (!key || qobject_type(key) != QTYPE_QSTRING) {
         parse_error(ctxt, peek, "key is not a string in object");
         goto out;
     }
Signature · 1 line
1.6.6.1
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net