[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 17/58] json: Fix lexer to include the bad charact
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v3 17/58] json: Fix lexer to include the bad character in JSON_ERROR token |
Date: |
Thu, 23 Aug 2018 18:39:44 +0200 |
json_lexer[] maps (lexer state, input character) to the new lexer
state. The input character is consumed unless the new state is
terminal and the input character doesn't belong to this token,
i.e. the state transition uses look-ahead. When this is the case,
input character '\0' would result in the same state transition.
TERMINAL_NEEDED_LOOKAHEAD() exploits this.
Except this is wrong for transitions to IN_ERROR. There, the
offending input character is in fact consumed: case IN_ERROR returns.
It isn't added to the JSON_ERROR token, though.
Fix that by making TERMINAL_NEEDED_LOOKAHEAD() return false for
transitions to IN_ERROR.
There's a slight complication. json_lexer_flush() passes input
character '\0' to flush an incomplete token. If this results in
JSON_ERROR, we'd now add the '\0' to the token. Suppress that.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
qobject/json-lexer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 980ba159d6..7c0875d225 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -76,7 +76,7 @@ QEMU_BUILD_BUG_ON((int)JSON_MIN <= (int)IN_START);
from OLD_STATE required lookahead. This happens whenever the table
below uses the TERMINAL macro. */
#define TERMINAL_NEEDED_LOOKAHEAD(old_state, terminal) \
- (json_lexer[(old_state)][0] == (terminal))
+ (terminal != IN_ERROR && json_lexer[(old_state)][0] == (terminal))
static const uint8_t json_lexer[][256] = {
/* Relies on default initialization to IN_ERROR! */
@@ -304,7 +304,7 @@ static int json_lexer_feed_char(JSONLexer *lexer, char ch,
bool flush)
assert(lexer->state <= ARRAY_SIZE(json_lexer));
new_state = json_lexer[lexer->state][(uint8_t)ch];
char_consumed = !TERMINAL_NEEDED_LOOKAHEAD(lexer->state, new_state);
- if (char_consumed) {
+ if (char_consumed && !flush) {
g_string_append_c(lexer->token, ch);
}
--
2.17.1
- [Qemu-devel] [PATCH v3 33/58] json: Have lexer call streamer directly, (continued)
- [Qemu-devel] [PATCH v3 33/58] json: Have lexer call streamer directly, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 39/58] json: Pass lexical errors and limit violations to callback, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 26/58] json: Leave rejecting invalid escape sequences to parser, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 31/58] json: remove useless return value from lexer/parser, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 22/58] json: Reject invalid UTF-8 sequences, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 29/58] json: Fix \uXXXX for surrogate pairs, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 37/58] json: Rename token JSON_ESCAPE & friends to JSON_INTERP, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 44/58] json: Fix latent parser aborts at end of input, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 28/58] json: Reject invalid \uXXXX, fix \u0000, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 19/58] json: Revamp lexer documentation, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 17/58] json: Fix lexer to include the bad character in JSON_ERROR token,
Markus Armbruster <=
- [Qemu-devel] [PATCH v3 18/58] json: Reject unescaped control characters, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 35/58] json: Don't pass null @tokens to json_parser_parse(), Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 36/58] json: Don't create JSON_ERROR tokens that won't be used, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 27/58] json: Simplify parse_string(), Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 10/58] check-qjson: Cover escaped characters more thoroughly, part 2, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 16/58] check-qjson: Cover interpolation more thoroughly, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 25/58] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8"), Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 04/58] check-qjson: Cover whitespace more thoroughly, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 13/58] check-qjson: Simplify utf8_string(), Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 32/58] json-parser: simplify and avoid JSONParserContext allocation, Markus Armbruster, 2018/08/23