From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=35601 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzDgg-0007fq-QA for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:44:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzDgf-0007wy-Er for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:44:18 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:37036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzDgf-0007wh-2l for qemu-devel@nongnu.org; Mon, 14 Mar 2011 15:44:17 -0400 Received: from d01dlp01.pok.ibm.com (d01dlp01.pok.ibm.com [9.56.224.56]) by e8.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p2EFOru5002095 for ; Mon, 14 Mar 2011 11:24:53 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 3537E38C8038 for ; Mon, 14 Mar 2011 15:44:00 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2EJhogF2441244 for ; Mon, 14 Mar 2011 15:43:50 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2EJho0o029226 for ; Mon, 14 Mar 2011 16:43:50 -0300 Message-ID: <4D7E6FF4.70503@us.ibm.com> Date: Mon, 14 Mar 2011 14:43:48 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1299877249-13433-1-git-send-email-aliguori@us.ibm.com> <1299877249-13433-9-git-send-email-aliguori@us.ibm.com> <20110314162229.013da3b3@doriath> In-Reply-To: <20110314162229.013da3b3@doriath> Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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: Luiz Capitulino Cc: Paolo Bonzini , qemu-devel@nongnu.org, Michael D Roth , Markus Armbruster On 03/14/2011 02:22 PM, Luiz Capitulino wrote: > 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": {}} This is a bug in the current QMP server. Here's how my new QMP server responds: {"QMP": {"version": {"qemu": {"micro": 50, "minor": 13, "major": 0}, "package": ""}, "capabilities": []}} {"error": {"class": "JSONParseError", "data": {"message": "Missing value in dict"}}} > { "execute": _ } > {"return": {}} Likewise, the new QMP server does not respond to this at all (which confuses me TBH). > Today, it handles this kind of input correctly: > > { "execute": xxxxx } > {"error": {"class": "JSONParsing", "desc": "Invalid JSON syntax", "data": {}}} The parser rejects this verses trying to get what it can out of it and passing that to QMP. The idea here is to be more graceful in dealing with bad input and trying to recover. > Although it also accepts broken stuff today, like: > > { "execute": ___"query-block" } This is really the server, not the parser. The new server doesn't accept this. I guess QMP today just ignores the incoming QObject in capabilities mode and always returns {}. You'll see the same thing with: { "execute": "not-a-valid-command" } {"return": {}} But once you're in command mode, it does the right thing. Regards, Anthony Liguori >> default: >> break;