From patchwork Wed Jun 1 17:14:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 98267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D8748B6F87 for ; Thu, 2 Jun 2011 06:54:11 +1000 (EST) Received: from localhost ([::1]:41183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRsQZ-0000k1-Uv for incoming@patchwork.ozlabs.org; Wed, 01 Jun 2011 16:54:08 -0400 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 Received: from localhost.localdomain ([32.97.110.59]) by mrelay.perfora.net (node=mrus4) with ESMTP (Nemesis) id 0MQiNZ-1Q2hYS1Urd-00U5ki; Wed, 01 Jun 2011 13:17:21 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 1 Jun 2011 12:14:51 -0500 Message-Id: <1306948500-15086-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4 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> X-Provags-ID: V02:K0:32NvMVGYNRfEE/SrCsB3y70j+M1ekDnFtGBbddvisvE mgttH7sQgDI526+kLGd5wMdQF3AJavAp7lIX0OyUWa1NRX+FNl ITIqLv/7FdZrvJQb7E0ey1jS+lgzxd21dxbtW1c+wMEzIpDH1P svwzWfpbaiJfKn5BetgEowUdNM2IALBRW9P2fQlFiXYPfXI0An GJ7yc0A1LEXarVdwRJfjzQNJOSAsnE0QIcOUQKLhTg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.208.4.195 Cc: aliguori@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v1][ 05/14] json-streamer: allow recovery after bad input X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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();