[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 02/56] check-qjson: Cover blank and lexically er
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH 02/56] check-qjson: Cover blank and lexically erroneous input |
Date: |
Fri, 10 Aug 2018 15:40:30 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Eric Blake <address@hidden> writes:
> On 08/08/2018 07:02 AM, Markus Armbruster wrote:
>> qobject_from_json() can return null without setting an error on
>> lexical errors. I call that a bug. Add test coverage to demonstrate
>> it.
>>
>> Signed-off-by: Markus Armbruster <address@hidden>
>> ---
>> tests/check-qjson.c | 36 +++++++++++++++++++++++++++++++++---
>> 1 file changed, 33 insertions(+), 3 deletions(-)
>>
>
>> +static void junk_input(void)
>> +{
>> + /* Note: junk within strings is covered elsewhere */
>> + Error *err = NULL;
>> + QObject *obj;
>> +
>> + obj = qobject_from_json("@", &err);
>
> Invalid token
>
>> + g_assert(!err); /* BUG */
>> + g_assert(obj == NULL);
>> +
>> + obj = qobject_from_json("[0\xFF]", &err);
>
> \xff stream reset, followed by unbalanced ]
>> + error_free_or_abort(&err);
>> + g_assert(obj == NULL);
>> +
>> + obj = qobject_from_json("00", &err);
>
> Invalid as a JSON number
>
>> + g_assert(!err); /* BUG */
>> + g_assert(obj == NULL);
>> +
>> + obj = qobject_from_json("[1e", &err);
>
> Incomplete as a JSON number
>
>> + g_assert(!err); /* BUG */
>> g_assert(obj == NULL);
>> }
>
> Is it also worth testing:
>
> "t" (incomplete as a JSON literal)
> "a" (not a valid JSON literal, but alphabetic and thus different from
> the "@" test above)
Yes, an invalid keyword is worth testing. The way the code works,
testing one should suffice.
> At any rate, with or without further tests this is good improved
> coverage dealt with in the rest of the series.
>
> Reviewed-by: Eric Blake <address@hidden>
Thanks!
- [Qemu-devel] [PATCH 00/56] json: Fixes, error reporting improvements, cleanups, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 09/56] check-qjson: Cover escaped characters more thoroughly, part 2, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 02/56] check-qjson: Cover blank and lexically erroneous input, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 01/56] check-qjson: Cover multiple JSON objects in same string, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 06/56] test-qga: Clean up how we test QGA synchronization, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 14/56] check-qjson qmp-test: Cover control characters more thoroughly, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 22/56] json: Report first rather than last parse error, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 05/56] qmp-test: Cover syntax and lexical errors, Markus Armbruster, 2018/08/08