From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRsNk-0000jT-NI for qemu-devel@nongnu.org; Wed, 01 Jun 2011 16:51:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRp2q-0007kO-D3 for qemu-devel@nongnu.org; Wed, 01 Jun 2011 13:21:54 -0400 Received: from mout.perfora.net ([74.208.4.195]:54015) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRp2p-0007jk-Ta for qemu-devel@nongnu.org; Wed, 01 Jun 2011 13:17:24 -0400 From: Michael Roth Date: Wed, 1 Jun 2011 12:14:51 -0500 Message-Id: <1306948500-15086-6-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1306948500-15086-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1306948500-15086-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v1][ 05/14] json-streamer: allow recovery after bad input List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com From: Anthony Liguori Once we detect a malformed message, make sure to reset our state. Signed-off-by: Michael Roth --- 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.0.4