From: Anthony Liguori <anthony@codemonkey.ws>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/4] qjson: Improve debugging
Date: Fri, 05 Feb 2010 09:54:39 -0600 [thread overview]
Message-ID: <4B6C3F3F.7010701@codemonkey.ws> (raw)
In-Reply-To: <20100205101217.7ec97899@doriath>
On 02/05/2010 06:12 AM, Luiz Capitulino wrote:
> On Thu, 04 Feb 2010 16:31:46 -0600
> Anthony Liguori<anthony@codemonkey.ws> wrote:
>
>
>> On 02/04/2010 02:13 PM, Luiz Capitulino wrote:
>>
>>> Add an assert() to qobject_from_jsonf() to assure that the returned
>>> QObject is not NULL. Currently this is duplicated in the callers.
>>>
>>> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
>>> ---
>>> qjson.c | 1 +
>>> 1 files changed, 1 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/qjson.c b/qjson.c
>>> index 9ad8a91..0922c06 100644
>>> --- a/qjson.c
>>> +++ b/qjson.c
>>> @@ -62,6 +62,7 @@ QObject *qobject_from_jsonf(const char *string, ...)
>>> obj = qobject_from_jsonv(string,&ap);
>>> va_end(ap);
>>>
>>> + assert(obj != NULL);
>>>
>>>
>> This is wrong. We may get JSON from an untrusted source. Callers need
>> to deal with failure appropriately.
>>
> What kind of untrusted source? This function is only used by handlers
> and assuming that the only possible error here is bad syntax, not having
> this check in the source will only duplicate it in the users.
>
I don't know yet, but there's nothing about this function that indicates
that it cannot handle malformed JSON. I don't think it's a reasonable
expectation either.
There are absolutely ways to mitigate this. You can use GCC macros to
enforce at compile time that the string argument is always a literal and
never a user supplied string.
Run time asserts are a terrible way to deal with reasonably expected errors.
Regards,
Anthony Liguori
next prev parent reply other threads:[~2010-02-05 15:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-04 20:13 [Qemu-devel] [PATCH v0 0/4]: QMP related fixes Luiz Capitulino
2010-02-04 20:13 ` [Qemu-devel] [PATCH 1/4] qjson: Improve debugging Luiz Capitulino
2010-02-04 22:31 ` Anthony Liguori
2010-02-05 9:13 ` Markus Armbruster
2010-02-05 12:13 ` Luiz Capitulino
2010-02-05 12:12 ` Luiz Capitulino
2010-02-05 15:54 ` Anthony Liguori [this message]
2010-02-05 17:14 ` Markus Armbruster
2010-02-08 11:22 ` Luiz Capitulino
2010-02-08 14:53 ` Anthony Liguori
2010-02-08 15:05 ` Luiz Capitulino
2010-02-04 20:13 ` [Qemu-devel] [PATCH 2/4] Monitor: remove unneeded checks Luiz Capitulino
2010-02-04 20:13 ` [Qemu-devel] [PATCH 3/4] QError: Don't abort on multiple faults Luiz Capitulino
2010-02-05 9:15 ` Markus Armbruster
2010-02-05 14:21 ` Markus Armbruster
2010-02-05 14:44 ` Luiz Capitulino
2010-02-05 15:15 ` Markus Armbruster
2010-02-05 17:07 ` Luiz Capitulino
2010-02-04 20:13 ` [Qemu-devel] [PATCH 4/4] QMP: Don't leak on connection close Luiz Capitulino
-- strict thread matches above, loose matches on Subject: below --
2010-02-08 19:01 [Qemu-devel] [PATCH v1 0/4]: QMP related fixes Luiz Capitulino
2010-02-08 19:01 ` [Qemu-devel] [PATCH 1/4] qjson: Improve debugging Luiz Capitulino
2010-02-10 21:41 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B6C3F3F.7010701@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).