From: Stefan Weil <sw@weilnetz.de>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: qemu-trivial@nongnu.org, Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] json-parser: Fix potential NULL pointer segfault
Date: Mon, 03 Sep 2012 19:14:27 +0200 [thread overview]
Message-ID: <5044E573.7010300@weilnetz.de> (raw)
In-Reply-To: <5044E092.4030300@weilnetz.de>
Am 03.09.2012 18:53, schrieb Stefan Weil:
> Am 03.09.2012 18:41, schrieb Luiz Capitulino:
>> On Sat, 1 Sep 2012 12:52:58 +0200
>> Stefan Weil <sw@weilnetz.de> wrote:
>>
>>> Report from smatch:
>>> json-parser.c:474 parse_object(62) error: potential null derefence
>>> 'dict'.
>>> json-parser.c:553 parse_array(75) error: potential null derefence
>>> 'list'.
>>>
>>> Label out can be called with list == NULL.
>>>
>>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>>> ---
>>> json-parser.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/json-parser.c b/json-parser.c
>>> index 457291b..c31c759 100644
>>> --- a/json-parser.c
>>> +++ b/json-parser.c
>>> @@ -471,7 +471,9 @@ static QObject *parse_object(JSONParserContext
>>> *ctxt, va_list *ap)
>>> out:
>>> parser_context_restore(ctxt, saved_ctxt);
>>> - QDECREF(dict);
>>> + if (dict) {
>>> + QDECREF(dict);
>>> + }
>>
>> I prefer changing QDECREF() to a nop if obj is NULL.
>
> That's fine for me, too. If everybody agrees, I'll send two new
> patches: one to change QDECREF, one to remove the if statements
> from other code locations which use the same pattern as
> my original patch.
>
> Cheers,
>
> - sw
>
>
What about modifying QOBJECT to return NULL if called with a NULL pointer?
That would be a more generic fix for the same problem.
In either case, the code will be a little larger and slower,
but that should not matter because it is not time critical.
Regards,
Stefan W.
WARNING: multiple messages have this Message-ID (diff)
From: Stefan Weil <sw@weilnetz.de>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: qemu-trivial@nongnu.org, Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] json-parser: Fix potential NULL pointer segfault
Date: Mon, 03 Sep 2012 19:14:27 +0200 [thread overview]
Message-ID: <5044E573.7010300@weilnetz.de> (raw)
In-Reply-To: <5044E092.4030300@weilnetz.de>
Am 03.09.2012 18:53, schrieb Stefan Weil:
> Am 03.09.2012 18:41, schrieb Luiz Capitulino:
>> On Sat, 1 Sep 2012 12:52:58 +0200
>> Stefan Weil <sw@weilnetz.de> wrote:
>>
>>> Report from smatch:
>>> json-parser.c:474 parse_object(62) error: potential null derefence
>>> 'dict'.
>>> json-parser.c:553 parse_array(75) error: potential null derefence
>>> 'list'.
>>>
>>> Label out can be called with list == NULL.
>>>
>>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>>> ---
>>> json-parser.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/json-parser.c b/json-parser.c
>>> index 457291b..c31c759 100644
>>> --- a/json-parser.c
>>> +++ b/json-parser.c
>>> @@ -471,7 +471,9 @@ static QObject *parse_object(JSONParserContext
>>> *ctxt, va_list *ap)
>>> out:
>>> parser_context_restore(ctxt, saved_ctxt);
>>> - QDECREF(dict);
>>> + if (dict) {
>>> + QDECREF(dict);
>>> + }
>>
>> I prefer changing QDECREF() to a nop if obj is NULL.
>
> That's fine for me, too. If everybody agrees, I'll send two new
> patches: one to change QDECREF, one to remove the if statements
> from other code locations which use the same pattern as
> my original patch.
>
> Cheers,
>
> - sw
>
>
What about modifying QOBJECT to return NULL if called with a NULL pointer?
That would be a more generic fix for the same problem.
In either case, the code will be a little larger and slower,
but that should not matter because it is not time critical.
Regards,
Stefan W.
next prev parent reply other threads:[~2012-09-03 17:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-01 10:52 [Qemu-trivial] [PATCH] json-parser: Fix potential NULL pointer segfault Stefan Weil
2012-09-01 10:52 ` [Qemu-devel] " Stefan Weil
2012-09-03 16:41 ` [Qemu-trivial] " Luiz Capitulino
2012-09-03 16:41 ` Luiz Capitulino
2012-09-03 16:53 ` [Qemu-trivial] " Stefan Weil
2012-09-03 16:53 ` Stefan Weil
2012-09-03 17:14 ` Stefan Weil [this message]
2012-09-03 17:14 ` Stefan Weil
2012-09-03 17:54 ` [Qemu-trivial] " Luiz Capitulino
2012-09-03 17:54 ` Luiz Capitulino
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=5044E573.7010300@weilnetz.de \
--to=sw@weilnetz.de \
--cc=aliguori@us.ibm.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.