From: Kevin Wolf <kwolf@redhat.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] xen_disk: cope with missing xenstore "params" node
Date: Fri, 11 Feb 2011 14:08:45 +0100 [thread overview]
Message-ID: <4D5534DD.6070705@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1102111250090.2826@kaball-desktop>
Am 11.02.2011 13:59, schrieb Stefano Stabellini:
> On Fri, 11 Feb 2011, Kevin Wolf wrote:
>> Am 11.02.2011 13:38, schrieb Stefano Stabellini:
>>> When disk is a cdrom and the drive is empty the "params" node in
>>> xenstore might be missing completely: cope with it instead of
>>> segfaulting.
>>>
>>> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>>>
>>>
>>> diff --git a/hw/xen_disk.c b/hw/xen_disk.c
>>> index 134ac33..e553c4c 100644
>>> --- a/hw/xen_disk.c
>>> +++ b/hw/xen_disk.c
>>> @@ -577,12 +577,13 @@ static int blk_init(struct XenDevice *xendev)
>>> {
>>> struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
>>> int index, qflags, have_barriers, info = 0;
>>> - char *h;
>>> + char *h = NULL;
>>>
>>> /* read xenstore entries */
>>> if (blkdev->params == NULL) {
>>> blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
>>> - h = strchr(blkdev->params, ':');
>>> + if (blkdev->params != NULL)
>>> + h = strchr(blkdev->params, ':');
>>
>> The coding style requires braces here.
>>
>
> Good point, I'll do.
>
>>> if (h != NULL) {
>>> blkdev->fileproto = blkdev->params;
>>> blkdev->filename = h+1;
>>
>> Let me add some more context:
>>
>> if (h != NULL) {
>> blkdev->fileproto = blkdev->params;
>> blkdev->filename = h+1;
>> *h = 0;
>> } else {
>> blkdev->fileproto = "<unset>";
>> blkdev->filename = blkdev->params;
>> }
>>
>> So in the NULL case we now have blkdev->filename = NULL. Doesn't this
>> just move the crash a few lines downwards when bdrv_open() tries to use
>> NULL as its filename?
>
> There is a check on blkdev->params being NULL few lines after so we just
> return.
Thanks, I missed that one.
> Maybe an explicit return -1 like in the appended patch here would be
> better?
> diff --git a/hw/xen_disk.c b/hw/xen_disk.c
> index 134ac33..fc0de14 100644
> --- a/hw/xen_disk.c
> +++ b/hw/xen_disk.c
> @@ -582,6 +582,9 @@ static int blk_init(struct XenDevice *xendev)
> /* read xenstore entries */
> if (blkdev->params == NULL) {
> blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
> + if (blkdev->params == NULL) {
> + return -1;
> + }
> h = strchr(blkdev->params, ':');
> if (h != NULL) {
> blkdev->fileproto = blkdev->params;
Yes, I think this is more explicit, and therefore easier to read.
Kevin
next prev parent reply other threads:[~2011-02-11 13:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-11 12:38 [Qemu-devel] [PATCH] xen_disk: cope with missing xenstore "params" node Stefano Stabellini
2011-02-11 12:49 ` Kevin Wolf
2011-02-11 12:59 ` Stefano Stabellini
2011-02-11 13:08 ` Kevin Wolf [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-06-24 14:50 stefano.stabellini
2011-06-24 15:06 ` Peter Maydell
2011-06-24 16:34 ` Stefano Stabellini
2011-06-24 16:34 ` Stefano Stabellini
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=4D5534DD.6070705@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
/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.