summary refs log tree commit diff stats
path: root/include/qapi/qmp/json-lexer.h
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-08-23 18:40:05 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-08-24 20:26:37 +0200
commit2cbd15aa6f4d4694376dd0d231d56e572ac870c1 (patch)
tree80bffd7131ee398510fb7961dfc0cb2982bed852 /include/qapi/qmp/json-lexer.h
parent61030280ca2d67bd63cb068250aee55849cd38ca (diff)
downloadfocaccia-qemu-2cbd15aa6f4d4694376dd0d231d56e572ac870c1.tar.gz
focaccia-qemu-2cbd15aa6f4d4694376dd0d231d56e572ac870c1.zip
json: Treat unwanted interpolation as lexical error
The JSON parser optionally supports interpolation.  The lexer
recognizes interpolation tokens unconditionally.  The parser rejects
them when interpolation is disabled, in parse_interpolation().
However, it neglects to set an error then, which can make
json_parser_parse() fail without setting an error.

Move the check for unwanted interpolation from the parser's
parse_interpolation() into the lexer's finite state machine.  When
interpolation is disabled, '%' is now handled like any other
unexpected character.

The next commit will improve how such lexical errors are handled.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180823164025.12553-39-armbru@redhat.com>
Diffstat (limited to 'include/qapi/qmp/json-lexer.h')
-rw-r--r--include/qapi/qmp/json-lexer.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/qapi/qmp/json-lexer.h b/include/qapi/qmp/json-lexer.h
index 8bce6ef676..afa84cb910 100644
--- a/include/qapi/qmp/json-lexer.h
+++ b/include/qapi/qmp/json-lexer.h
@@ -33,12 +33,12 @@ typedef enum json_token_type {
 } JSONTokenType;
 
 typedef struct JSONLexer {
-    int state;
+    int start_state, state;
     GString *token;
     int x, y;
 } JSONLexer;
 
-void json_lexer_init(JSONLexer *lexer);
+void json_lexer_init(JSONLexer *lexer, bool enable_interpolation);
 
 void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);