]> git.proxmox.com Git - mirror_qemu.git/commit - qobject/json-streamer.c
json: Fix streamer not to ignore trailing unterminated structures
authorMarkus Armbruster <armbru@redhat.com>
Thu, 23 Aug 2018 16:40:12 +0000 (18:40 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Fri, 24 Aug 2018 18:26:37 +0000 (20:26 +0200)
commitf9277915ee7b2654f5347c4c261c8a0651fdd561
treefdd3e61e5c1e072b9fc24cdb6fac78a4d551d942
parente06d008ac833ac220b920f4d8858e6f62f7a59f9
json: Fix streamer not to ignore trailing unterminated structures

json_message_process_token() accumulates tokens until it got the
sequence of tokens that comprise a single JSON value (it counts curly
braces and square brackets to decide).  It feeds those token sequences
to json_parser_parse().  If a non-empty sequence of tokens remains at
the end of the parse, it's silently ignored.  check-qjson.c cases
unterminated_array(), unterminated_array_comma(), unterminated_dict(),
unterminated_dict_comma() demonstrate this bug.

Fix as follows.  Introduce a JSON_END_OF_INPUT token.  When the
streamer receives it, it feeds the accumulated tokens to
json_parser_parse().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180823164025.12553-46-armbru@redhat.com>
include/qapi/qmp/json-lexer.h
qobject/json-lexer.c
qobject/json-streamer.c
tests/check-qjson.c