json-streamer: allow recovery after bad input

Once we detect a malformed message, make sure to reset our state.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Anthony Liguori 2011-06-01 12:14:51 -05:00
parent ef749d07e7
commit 55f8301f76
1 changed files with 6 additions and 2 deletions

View File

@ -51,8 +51,12 @@ static void json_message_process_token(JSONLexer *lexer, QString *token, JSONTok
qlist_append(parser->tokens, dict);
if (parser->brace_count == 0 &&
parser->bracket_count == 0) {
if (parser->brace_count < 0 ||
parser->bracket_count < 0 ||
(parser->brace_count == 0 &&
parser->bracket_count == 0)) {
parser->brace_count = 0;
parser->bracket_count = 0;
parser->emit(parser, parser->tokens);
QDECREF(parser->tokens);
parser->tokens = qlist_new();