Skip to content

json: Fixes, error reporting improvements, cleanups

Markus Armbruster qemu-devel 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest58 patches 3 repliesIn review
  2. v260 patches 29 repliesSuperseded
  3. v156 patches 105 repliesSuperseded

Changes in v3 from the cover letter · 17 lines

* Trivially rebased
* Old PATCH 41,51-52 punted to a future series
* PATCH 01 was PATCH 56 [Eric]
* PATCH 58 is new (but trivial)
* R-bys kept
* PATCH 01,06,11
- Commit message improved [Eric]
* PATCH 08,10,12,14
- from_json_str()'s unusual parameter order tidied up [Eric]
* PATCH 15,18-19,24,26,37
- Refer to RFC 8259 instead of obsolete RFC 7159
* PATCH 37-39,40
- Abbreviate interpolation as INTERP instead of INTERPOL [Eric]
* PATCH 39
- Stale comment updated
* PATCH 45
- Comma after JSON_END_OF_INPUT

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/58docs/interop/qmp-spec: How to force known good parser statedocs/interop/qmp-spec.txt+28 -140 replies
2/58check-qjson: Cover multiple JSON objects in same stringtests/check-qjson.c+20 -00 replies
3/58check-qjson: Cover blank and lexically erroneous inputtests/check-qjson.c+37 -30 replies
4/58check-qjson: Cover whitespace more thoroughlytests/check-qjson.c+1 -10 replies
5/58qmp-cmd-test: Split off qmp-testMAINTAINERS tests/Makefile.include tests/qmp-cmd-test.c +1 more+219 -1910 replies
6/58qmp-test: Cover syntax and lexical errorstests/libqtest.c tests/libqtest.h tests/qmp-test.c+68 -12 replies
7/58test-qga: Clean up how we test QGA synchronizationtests/libqtest.c tests/libqtest.h tests/test-qga.c+25 -190 replies
8/58check-qjson: Cover escaped characters more thoroughly, part 1tests/check-qjson.c+57 -390 replies
9/58check-qjson: Streamline escaped_string()'s test stringstests/check-qjson.c+1 -110 replies
10/58check-qjson: Cover escaped characters more thoroughly, part 2tests/check-qjson.c+53 -90 replies
11/58check-qjson: Consolidate partly redundant string teststests/check-qjson.c+14 -500 replies
12/58check-qjson: Cover UTF-8 in single quoted stringstests/check-qjson.c+214 -2130 replies
13/58check-qjson: Simplify utf8_string()tests/check-qjson.c+9 -440 replies
14/58check-qjson: Fix utf8_string() to test all invalid sequencestests/check-qjson.c+28 -50 replies
15/58check-qjson qmp-test: Cover control characters more thoroughlytests/check-qjson.c tests/qmp-test.c+44 -60 replies
16/58check-qjson: Cover interpolation more thoroughlytests/check-qjson.c+102 -640 replies
17/58json: Fix lexer to include the bad character in JSON_ERROR tokenqobject/json-lexer.c+2 -20 replies
18/58json: Reject unescaped control charactersqobject/json-lexer.c tests/check-qjson.c tests/qmp-test.c+5 -90 replies
19/58json: Revamp lexer documentationqobject/json-lexer.c+71 -90 replies
20/58json: Tighten and simplify qstring_from_escaped_str()'s loopqobject/json-parser.c+7 -230 replies
21/58check-qjson: Document we expect invalid UTF-8 to be rejectedtests/check-qjson.c+71 -800 replies
22/58json: Reject invalid UTF-8 sequencesinclude/qemu/unicode.h qobject/json-parser.c tests/check-qjson.c +1 more+122 -1050 replies
23/58json: Report first rather than last parse errorqobject/json-parser.c+4 -40 replies
24/58json: Leave rejecting invalid UTF-8 to parserqobject/json-lexer.c+2 -40 replies
25/58json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8")qobject/json-lexer.c qobject/json-parser.c tests/check-qjson.c+3 -90 replies
26/58json: Leave rejecting invalid escape sequences to parserqobject/json-lexer.c qobject/json-parser.c+37 -910 replies
27/58json: Simplify parse_string()qobject/json-parser.c+19 -230 replies
28/58json: Reject invalid \uXXXX, fix \u0000qobject/json-parser.c tests/check-qjson.c+17 -590 replies
29/58json: Fix \uXXXX for surrogate pairsqobject/json-parser.c tests/check-qjson.c+40 -230 replies
30/58check-qjson: Fix and enable utf8_string()'s disabled parttests/check-qjson.c+3 -80 replies
31/58json: remove useless return value from lexer/parserinclude/qapi/qmp/json-lexer.h include/qapi/qmp/json-streamer.h qobject/json-lexer.c +1 more+16 -230 replies
32/58json-parser: simplify and avoid JSONParserContext allocationqobject/json-parser.c+9 -320 replies
33/58json: Have lexer call streamer directlyinclude/qapi/qmp/json-lexer.h include/qapi/qmp/json-streamer.h qobject/json-lexer.c +1 more+17 -180 replies
34/58json: Redesign the callback to consume JSON valuesinclude/qapi/qmp/json-parser.h include/qapi/qmp/json-streamer.h monitor.c +7 more+39 -540 replies
35/58json: Don't pass null @tokens to json_parser_parse()qobject/json-parser.c qobject/json-streamer.c+12 -170 replies
36/58json: Don't create JSON_ERROR tokens that won't be usedqobject/json-streamer.c+2 -40 replies
37/58json: Rename token JSON_ESCAPE & friends to JSON_INTERPinclude/qapi/qmp/json-lexer.h qobject/json-lexer.c qobject/json-parser.c+37 -370 replies
38/58json: Treat unwanted interpolation as lexical errorinclude/qapi/qmp/json-lexer.h qobject/json-lexer.c qobject/json-parser.c +2 more+25 -190 replies
39/58json: Pass lexical errors and limit violations to callbackinclude/qapi/qmp/qerror.h monitor.c qga/main.c +4 more+33 -250 replies
40/58json: Leave rejecting invalid interpolation to parserqobject/json-lexer.c qobject/json-parser.c tests/check-qjson.c+9 -390 replies
41/58json: Replace %I64d, %I64u by %PRId64, %PRIu64qobject/json-parser.c tests/check-qjson.c+16 -40 replies
42/58json: Improve names of lexer states related to numbersqobject/json-lexer.c+17 -170 replies
43/58qjson: Fix qobject_from_json() & friends for multiple valuesqobject/qjson.c tests/check-qjson.c+17 -80 replies
44/58json: Fix latent parser aborts at end of inputqobject/json-parser.c+0 -20 replies
45/58json: Fix streamer not to ignore trailing unterminated structuresinclude/qapi/qmp/json-lexer.h qobject/json-lexer.c qobject/json-streamer.c +1 more+15 -40 replies
46/58json: Assert json_parser_parse() consumes all tokens on successqobject/json-parser.c+1 -00 replies
47/58qjson: Have qobject_from_json() & friends reject empty and blankblock.c qapi/qobject-input-visitor.c qobject/qjson.c +1 more+14 -120 replies
48/58json: Enforce token count and size limits more tightlyqobject/json-streamer.c+18 -180 replies
49/58json: Streamline json_message_process_token()qobject/json-streamer.c+5 -80 replies
50/58json: Unbox tokens queue in JSONMessageParserinclude/qapi/qmp/json-streamer.h qobject/json-parser.c qobject/json-streamer.c+12 -210 replies
51/58json: Make JSONToken opaque outside json-parser.cinclude/qapi/qmp/json-parser.h include/qapi/qmp/json-streamer.h qobject/json-parser.c +1 more+24 -140 replies
52/58qobject: Drop superfluous includes of qemu-common.hinclude/qapi/qmp/json-parser.h qobject/json-lexer.c qobject/json-streamer.c +6 more+0 -90 replies
53/58json: Clean up headersinclude/qapi/qmp/json-parser.h include/qapi/qmp/json-streamer.h monitor.c +7 more+51 -760 replies
54/58tests/drive_del-test: Fix harmless JSON interpolation bugtests/drive_del-test.c+6 -20 replies
55/58json: Keep interpolation state in JSONParserContextqobject/json-parser.c+30 -290 replies
56/58json: Improve safety of qobject_from_jsonf_nofail() & friendsqobject/json-parser.c tests/check-qjson.c+17 -120 replies
57/58json: Support %% in JSON strings when interpolatingqobject/json-parser.c tests/check-qjson.c+4 -30 replies
58/58json: Update references to RFC 7159 to RFC 8259include/qapi/qmp/qnum.h qapi/introspect.json qobject/json-parser.c+3 -31 reply

Reviews trailers per patch

All 58 patches have a Reviewed-by or Acked-by.

PatchEric BlakeMarkus ArmbrusterThomas Huth
1/58R-b
2/58R-b
3/58R-b
4/58R-b
5/58R-b
6/58R-b
7/58R-b
8/58R-b
9/58R-b
10/58R-b
11/58R-b
12/58R-b
13/58R-b
14/58R-b
15/58R-b
16/58R-b
17/58R-b
18/58R-b
19/58R-b
20/58R-b
21/58R-b
22/58R-b
23/58R-b
24/58R-b
25/58R-b
26/58R-b
27/58R-b
28/58R-b
29/58R-b
30/58R-b
31/58R-b R-b
32/58R-b
33/58R-b
34/58R-b
35/58R-b
36/58R-b
37/58R-b
38/58R-b
39/58R-b
40/58R-b
41/58R-b
42/58R-b
43/58R-b
44/58R-b
45/58R-b
46/58R-b
47/58R-b
48/58R-b
49/58R-b
50/58R-b
51/58R-b
52/58R-b
53/58R-b
54/58R-b
55/58R-b
56/58R-b
57/58R-b
58/58R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v3 thread

Cover letter [Qemu-devel] [PATCH v3 00/58] json: Fixes, error reporting improvements, cleanups

JSON is such a simple language, so writing a parser should be easy, shouldn't it? Well, the evidence is in, and it's a lot of patches. Summary of fixes:

* Reject ASCII control characters in strings as RFC 7159 specifies

* Reject all invalid UTF-8 sequences, not just some

* Reject invalid \uXXXX escapes

* Implement \uXXXX surrogate pairs as specified by RFC 7159

* Don't ignore \u0000 silently, map it to \xC0\80 (modified UTF-8)

* qobject_from_json() is ridicilously broken for input containing more than one value, fix

* Don't ignore trailing unterminated structures

* Less cavalierly cruel error reporting

Topped off with tests and cleanups.

If you're into this kind of disaster relief, commit c7a3f25200c "qapi.py: Restructure lexer and parser" was even funnier.

v3:
* Trivially rebased
* Old PATCH 41,51-52 punted to a future series
* PATCH 01 was PATCH 56 [Eric]
* PATCH 58 is new (but trivial)
* R-bys kept
* PATCH 01,06,11
- Commit message improved [Eric]
* PATCH 08,10,12,14
- from_json_str()'s unusual parameter order tidied up [Eric]
* PATCH 15,18-19,24,26,37
- Refer to RFC 8259 instead of obsolete RFC 7159
* PATCH 37-39,40
- Abbreviate interpolation as INTERP instead of INTERPOL [Eric]
* PATCH 39
- Stale comment updated
* PATCH 45
- Comma after JSON_END_OF_INPUT
v2:
* Rebased
* PATCH 01,11-14,16-18,20,22-23,29-36,41,43,45-50,53-55 otherwise unchanged
* PATCH 57-60 are new
* R-bys kept unless noted otherwise
* PATCH 02
- Cover unrecognized keyword [Eric]
* PATCH 03
- Cover \r [Eric]
* PATCH 04-05
- Comments touched up [Eric]
* PATCH 06
- Use qmp_fd_send_raw() just for "\xff" [Eric]
* PATCH 07
- Plug memory leak [Eric]
* PATCH 08
- Delay adding coverage for \' until PATCH 09
* PATCH 09
- Cover \\\0
- Drop duplicated test case (editing accident) [Eric]
- Improve surrogate coverage
* PATCH 10
- Don't lose test coverage for \" and \'
- R-by dropped
* PATCH 15,27,38-39
- Cover unkown interpolation specification
- Cover attempt to interpolate into JSON string
- R-by of PATCH 15 dropped
* PATCH 19
- Tweak loop control once more
- R-by dropped
* PATCH 21,26
- Update for tweak to PATCH 19
- I might still drop redundant masking [Eric]
* PATCH 24
- Commit message improved
* PATCH 25
- Comment improvement [Eric]
- Commit message tweaked
* PATCH 28
- Fix error message to show both halves of an invalid surrogate pair

    [Eric]

- Fix unpaired leading surrogate followed by \u escape [Paolo]
* PATCH 36
- I might still rename JSON_INTERPOL & friends [Eric]
* PATCH 37
- Document lexing interpolations is now optional [Eric]
- Move deletion of a redundant assignment from PATCH 51 [Eric]
* PATCH 37,42,51-52
- De-duplicate state transitions common to IN_START and IN_START_INTERPOL [Eric]
* PATCH 38
- Commit message tweaked
* PATCH 39
- More legible commit message [Eric]
- Comment fix [Eric]
* PATCH 40
- Commit message typo [Eric]
* PATCH 44
- Commit message tab damage [Eric]
* PATCH 56
- More on QGA synchronization [Eric]
- I might still move this earlier in the series

Marc-André Lureau (2):
json: remove useless return value from lexer/parser
json-parser: simplify and avoid JSONParserContext allocation

Markus Armbruster (56):
docs/interop/qmp-spec: How to force known good parser state
check-qjson: Cover multiple JSON objects in same string
check-qjson: Cover blank and lexically erroneous input
check-qjson: Cover whitespace more thoroughly
qmp-cmd-test: Split off qmp-test
qmp-test: Cover syntax and lexical errors
test-qga: Clean up how we test QGA synchronization
check-qjson: Cover escaped characters more thoroughly, part 1
check-qjson: Streamline escaped_string()'s test strings
check-qjson: Cover escaped characters more thoroughly, part 2
check-qjson: Consolidate partly redundant string tests
check-qjson: Cover UTF-8 in single quoted strings
check-qjson: Simplify utf8_string()
check-qjson: Fix utf8_string() to test all invalid sequences check-qjson qmp-test: Cover control characters more thoroughly
check-qjson: Cover interpolation more thoroughly
json: Fix lexer to include the bad character in JSON_ERROR token
json: Reject unescaped control characters
json: Revamp lexer documentation
json: Tighten and simplify qstring_from_escaped_str()'s loop
check-qjson: Document we expect invalid UTF-8 to be rejected
json: Reject invalid UTF-8 sequences
json: Report first rather than last parse error
json: Leave rejecting invalid UTF-8 to parser
json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8")
json: Leave rejecting invalid escape sequences to parser
json: Simplify parse_string()
json: Reject invalid \uXXXX, fix \u0000
json: Fix \uXXXX for surrogate pairs
check-qjson: Fix and enable utf8_string()'s disabled part
json: Have lexer call streamer directly
json: Redesign the callback to consume JSON values
json: Don't pass null @tokens to json_parser_parse()
json: Don't create JSON_ERROR tokens that won't be used
json: Rename token JSON_ESCAPE & friends to JSON_INTERP
json: Treat unwanted interpolation as lexical error
json: Pass lexical errors and limit violations to callback
json: Leave rejecting invalid interpolation to parser
json: Replace %I64d, %I64u by %PRId64, %PRIu64
json: Improve names of lexer states related to numbers
qjson: Fix qobject_from_json() & friends for multiple values
json: Fix latent parser aborts at end of input
json: Fix streamer not to ignore trailing unterminated structures
json: Assert json_parser_parse() consumes all tokens on success
qjson: Have qobject_from_json() & friends reject empty and blank
json: Enforce token count and size limits more tightly
json: Streamline json_message_process_token()
json: Unbox tokens queue in JSONMessageParser
json: Make JSONToken opaque outside json-parser.c
qobject: Drop superfluous includes of qemu-common.h
json: Clean up headers
tests/drive_del-test: Fix harmless JSON interpolation bug
json: Keep interpolation state in JSONParserContext
json: Improve safety of qobject_from_jsonf_nofail() & friends
json: Support %% in JSON strings when interpolating
json: Update references to RFC 7159 to RFC 8259

 MAINTAINERS                      |    1 +
 block.c                          |    5 -
 docs/interop/qmp-spec.txt        |   42 +-
 include/qapi/qmp/json-lexer.h    |   56 --
 include/qapi/qmp/json-parser.h   |   36 +-
 include/qapi/qmp/json-streamer.h |   46 --
 include/qapi/qmp/qerror.h        |    3 -
 include/qapi/qmp/qnum.h          |    2 +-
 include/qemu/unicode.h           |    1 +
 monitor.c                        |   21 +-
 qapi/introspect.json             |    2 +-
 qapi/qmp-dispatch.c              |    1 -
 qapi/qobject-input-visitor.c     |    5 -
 qga/main.c                       |   15 +-
 qobject/json-lexer.c             |  317 ++++-----
 qobject/json-parser-int.h        |   54 ++
 qobject/json-parser.c            |  379 +++++------
 qobject/json-streamer.c          |  126 ++--
 qobject/qbool.c                  |    1 -
 qobject/qjson.c                  |   31 +-
 qobject/qlist.c                  |    1 -
 qobject/qnull.c                  |    1 -
 qobject/qnum.c                   |    1 -
 qobject/qobject.c                |    1 -
 qobject/qstring.c                |    1 -
 tests/Makefile.include           |    3 +
 tests/check-qjson.c              | 1058 ++++++++++++++++--------------
 tests/drive_del-test.c           |    8 +-
 tests/libqtest.c                 |   57 +-
 tests/libqtest.h                 |   13 +
 tests/qmp-cmd-test.c             |  213 ++++++
 tests/qmp-test.c                 |  252 ++-----
 tests/test-qga.c                 |    3 +-
 util/unicode.c                   |   69 +-
 34 files changed, 1484 insertions(+), 1341 deletions(-)
 delete mode 100644 include/qapi/qmp/json-lexer.h
 delete mode 100644 include/qapi/qmp/json-streamer.h
 create mode 100644 qobject/json-parser-int.h
 create mode 100644 tests/qmp-cmd-test.c
Signature · 1 line
2.17.1