json-parser: Fix segfault on malformed input
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.
Signed-off-by Kevin Wolf <[email protected]>
--- json-parser.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
json-parser.c +1 -1
@@ -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
Aurelien Jarno
AppliedQuoted 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.Signed-off-by Kevin Wolf <[email protected]>
Thanks, applied.
Quoted 23 lines
--- json-parser.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)json-parser.c +1
-1@@ -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