qemu-xen: fix segfault with empty cdroms
PATCH 1/1 qemu-xen: fix segfault with empty cdroms
When the cdrom is empty the params node in xenstore might be missing completely, cope with it instead of segfaulting.
hw/xen_disk.c +3 -2
@@ -582,12 +582,13 @@ static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int mode, 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,':' );if (h !=NULL ) { blkdev->fileproto = blkdev->params; blkdev->filename = h+1 ;
Stefano Stabellini writes ("[Xen-devel] [PATCH] qemu-xen: fix segfault with empty cdroms"):
Quoted 2 lines
When the cdrom is empty the params node in xenstore might be missing completely, cope with it instead of segfaulting.
...
hw/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 591
Quoted 4 lines
hw/xen_disk.c +2
-1blkdev->params =xenstore_read_be_str (&blkdev->xendev,"params" ); - h =strchr (blkdev->params,':' ); +if (blkdev->params !=NULL ) + h =strchr (blkdev->params,':' );
So blkdev->params may be 0. In that case, we end up with:
blkdev->fileproto = "<unset>";
blkdev->filename = blkdev->params;so now ->filename may be 0. Eventually,
if (bdrv_open2(blkdev->bs, blkdev->filename, qflags,
bdrv_find_format(blkdev->fileproto)) != 0) {Isn't that going to crash ?
Perhaps a clause needs to be added to:
/* do we have all we need? */
if (blkdev->params == NULL ||
blkdev->mode == NULL ||
blkdev->type == NULL ||
blkdev->dev == NULL)
return -1;Ian.
Quoted 21 lines · Ian Jackson
Stefano Stabellini writes ("[Xen-devel] [PATCH] qemu-xen: fix segfault with empty cdroms"):
Quoted 2 lines
When the cdrom is empty the params node in xenstore might be missing completely, cope with it instead of segfaulting.
...
hw/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 591
Quoted 4 lines
hw/xen_disk.c +2
-1blkdev->params =xenstore_read_be_str (&blkdev->xendev,"params" ); - h =strchr (blkdev->params,':' ); +if (blkdev->params !=NULL ) + h =strchr (blkdev->params,':' );So
blkdev->paramsmay be 0. In that case, we end up with:blkdev->fileproto = "<unset>"; blkdev->filename = blkdev->params;so now ->filename may be 0. Eventually,
if (bdrv_open2(blkdev->bs, blkdev->filename, qflags, bdrv_find_format(blkdev->fileproto)) != 0) {Isn't that going to crash ?
Quoted 8 lines
Perhaps a clause needs to be added to:
/* do we have all we need? */ if (blkdev->params == NULL || blkdev->mode == NULL || blkdev->type == NULL || blkdev->dev == NULL) return -1;
No need, in fact if blkdev->params is NULL we return -1 right here.
Stefano Stabellini writes ("Re: [Xen-devel] [PATCH] qemu-xen: fix segfault with empty cdroms"):
Quoted 1 line
No need, in fact if
blkdev->paramsis NULL we return -1 right here.
Oh, yes, sorry, I misread the earlier thing as assigning to params. I'll apply your patch.
Ian.