qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: [PATCH 08/11] json-lexer: reset the lexer state on an i


From: Luiz Capitulino
Subject: [Qemu-devel] Re: [PATCH 08/11] json-lexer: reset the lexer state on an invalid token
Date: Mon, 14 Mar 2011 16:22:29 -0300

On Fri, 11 Mar 2011 15:00:46 -0600
Anthony Liguori <address@hidden> 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 <address@hidden>
> 
> 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;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]