Patchwork qcow2: Fix segfault when qcow2 preallocate fails

login
register
mail settings
Submitter Stefan Hajnoczi
Date Oct. 26, 2010, 1:23 p.m.
Message ID <1288099399-10010-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/69250/
State New
Headers show

Comments

Stefan Hajnoczi - Oct. 26, 2010, 1:23 p.m.
When an image is created with -o preallocate, ensure that we only call
preallocate() if the image was indeed opened successfully.  Also use
bdrv_delete() instead of bdrv_close() to avoid leaking the
BlockDriverState structure.

This fixes the segfault reported at
https://bugzilla.redhat.com/show_bug.cgi?id=646538.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
Here's a fix for the segfault.

 block/qcow2.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
Kevin Wolf - Oct. 26, 2010, 1:48 p.m.
Am 26.10.2010 15:23, schrieb Stefan Hajnoczi:
> When an image is created with -o preallocate, ensure that we only call
> preallocate() if the image was indeed opened successfully.  Also use
> bdrv_delete() instead of bdrv_close() to avoid leaking the
> BlockDriverState structure.
> 
> This fixes the segfault reported at
> https://bugzilla.redhat.com/show_bug.cgi?id=646538.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Looks good for stable-0.13. In master we'll have the new qcow_create2
implementation as soon as Anthony pulls, so it doesn't apply there.

Kevin
Stefan Hajnoczi - Oct. 26, 2010, 2:04 p.m.
On Tue, Oct 26, 2010 at 2:48 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 26.10.2010 15:23, schrieb Stefan Hajnoczi:
>> When an image is created with -o preallocate, ensure that we only call
>> preallocate() if the image was indeed opened successfully.  Also use
>> bdrv_delete() instead of bdrv_close() to avoid leaking the
>> BlockDriverState structure.
>>
>> This fixes the segfault reported at
>> https://bugzilla.redhat.com/show_bug.cgi?id=646538.
>>
>> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> Looks good for stable-0.13. In master we'll have the new qcow_create2
> implementation as soon as Anthony pulls, so it doesn't apply there.

I forgot about that :).  Thanks Kevin.

Stefan

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index ee3481b..0fceb0d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1059,9 +1059,11 @@  exit:
         BlockDriverState *bs;
         BlockDriver *drv = bdrv_find_format("qcow2");
         bs = bdrv_new("");
-        bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR, drv);
-        ret = preallocate(bs);
-        bdrv_close(bs);
+        ret = bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR, drv);
+        if (ret == 0) {
+            ret = preallocate(bs);
+        }
+        bdrv_delete(bs);
     }
 
     return ret;