From 93d38b3b28c2445d1f1c47903491603a2da7d1e8 Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Mon, 5 Mar 2012 17:44:31 -0500 Subject: [PATCH 64/98] json-streamer: allow recovery after bad input Once we detect a malformed message, make sure to reset our state. Signed-off-by: Michael Roth Signed-off-by: Anthony Liguori (cherry picked from commit 55f8301f7665eeef6d454cf4843c3f67b067f357) Signed-off-by: Jeff Cody Signed-off-by: Michal Novotny --- json-streamer.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/json-streamer.c b/json-streamer.c index f7e7a68..549e9b7 100644 --- a/json-streamer.c +++ b/json-streamer.c @@ -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(); -- 1.7.7.6