]> xenbits.xensource.com Git - libvirt.git/commit
json: reject trailing garbage
authorEric Blake <eblake@redhat.com>
Mon, 22 Jun 2015 20:18:34 +0000 (14:18 -0600)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 25 Jun 2015 07:11:15 +0000 (09:11 +0200)
commit7cd991b74c5f22ead826a71d1427354b1a80915e
treed225ec11081fd8ec8b3f86047aea8f343f23017c
parent54dbba5bc3e5bc177b0d806849e44d81192d1168
json: reject trailing garbage

Yajl 2 has a nice feature that it can be configured whether to
allow multiple JSON objects parsed from a single stream, defaulting
to off.  And yajl 1.0.12 at least provided a way to tell if all
input bytes were parsed, or if trailing bytes remained after a
valid JSON object was parsed.  But we target RHEL 6 yajl 1.0.7,
which has neither of these.  So fake it by always parsing '[...]'
instead, so that trailing garbage either trips up the array parse,
or is easily detected when unwrapping the result.

* src/util/virjson.c (virJSONValueFromString): With older json,
wrap text to avoid trailing garbage.
* tests/jsontest.c (mymain): Add tests for this.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/virjson.c
tests/jsontest.c