From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33420 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnsPI-0000fN-T7 for qemu-devel@nongnu.org; Fri, 11 Feb 2011 07:47:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PnsPE-0007um-Jb for qemu-devel@nongnu.org; Fri, 11 Feb 2011 07:47:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PnsPE-0007uV-BO for qemu-devel@nongnu.org; Fri, 11 Feb 2011 07:47:24 -0500 Message-ID: <4D553042.4020502@redhat.com> Date: Fri, 11 Feb 2011 13:49:06 +0100 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] xen_disk: cope with missing xenstore "params" node References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefano Stabellini Cc: qemu-devel@nongnu.org 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 > > > 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. > 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 = ""; 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? Kevin