From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=50761 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzDLi-0005Bz-2H for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:22:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzDLe-0003jo-LP for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:22:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14047) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzDLe-0003ja-8v for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:22:34 -0400 Date: Mon, 14 Mar 2011 16:22:29 -0300 From: Luiz Capitulino Message-ID: <20110314162229.013da3b3@doriath> In-Reply-To: <1299877249-13433-9-git-send-email-aliguori@us.ibm.com> References: <1299877249-13433-1-git-send-email-aliguori@us.ibm.com> <1299877249-13433-9-git-send-email-aliguori@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 08/11] json-lexer: reset the lexer state on an invalid token List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Paolo Bonzini , Michael@gnu.org, qemu-devel@nongnu.org, Roth , Markus Armbruster On Fri, 11 Mar 2011 15:00:46 -0600 Anthony Liguori wrote: > Not everything handles errors from json parsing gracefully. By at least > resetting the lexer, we'll start generating valid tokens again and hopefully > recover the stream. > > Signed-off-by: Anthony Liguori > > diff --git a/json-lexer.c b/json-lexer.c > index c736f42..834d7af 100644 > --- a/json-lexer.c > +++ b/json-lexer.c > @@ -303,6 +303,9 @@ static int json_lexer_feed_char(JSONLexer *lexer, char ch) > new_state = IN_START; > break; > case ERROR: > + QDECREF(lexer->token); > + lexer->token = qstring_new(); > + new_state = IN_START; > return -EINVAL; This makes the parser accept broken input like: { "execute": xxxxx } {"return": {}} { "execute": _ } {"return": {}} Today, it handles this kind of input correctly: { "execute": xxxxx } {"error": {"class": "JSONParsing", "desc": "Invalid JSON syntax", "data": {}}} Although it also accepts broken stuff today, like: { "execute": ___"query-block" } > default: > break;