[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.1 19/24] block/cow: Avoid use of uninitialized
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL for-2.1 19/24] block/cow: Avoid use of uninitialized cow_bs in error path |
Date: |
Tue, 1 Jul 2014 10:48:52 +0200 |
From: Peter Maydell <address@hidden>
Commit 25814e8987 introduced an error-exit code path which does
a "goto exit" before the cow_bs variable is initialized, meaning
we would call bdrv_unref() on an uninitialized variable and
likely segfault. Fix this by moving the NULL-initialization
to the top of the function and making the exit code path handle
the case where it is NULL.
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/cow.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/block/cow.c b/block/cow.c
index 8f81ee6..6ee4833 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -332,7 +332,7 @@ static int cow_create(const char *filename, QemuOpts *opts,
Error **errp)
char *image_filename = NULL;
Error *local_err = NULL;
int ret;
- BlockDriverState *cow_bs;
+ BlockDriverState *cow_bs = NULL;
/* Read out options */
image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
@@ -344,7 +344,6 @@ static int cow_create(const char *filename, QemuOpts *opts,
Error **errp)
goto exit;
}
- cow_bs = NULL;
ret = bdrv_open(&cow_bs, filename, NULL, NULL,
BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
if (ret < 0) {
@@ -383,7 +382,9 @@ static int cow_create(const char *filename, QemuOpts *opts,
Error **errp)
exit:
g_free(image_filename);
- bdrv_unref(cow_bs);
+ if (cow_bs) {
+ bdrv_unref(cow_bs);
+ }
return ret;
}
--
1.9.3
- [Qemu-devel] [PULL for-2.1 11/24] qdev: drop iothread property type, (continued)
- [Qemu-devel] [PULL for-2.1 11/24] qdev: drop iothread property type, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 12/24] virtio-blk: remove need for explicit x-data-plane=on option, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 13/24] qemu-img create: add 'nocow' option, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 14/24] iotests: Simplify qemu-iotests-quick.sh, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 15/24] iotests: Add qemu tests to quick group, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 17/24] block: make 'top' argument to block-commit optional, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 16/24] iotests: Add more tests to quick group, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 18/24] block: simplify bdrv_find_base() and bdrv_find_overlay(), Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 19/24] block/cow: Avoid use of uninitialized cow_bs in error path,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL for-2.1 20/24] qapi: Change back sector-count to sectors-count in quorum QAPI events., Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 21/24] block: add QAPI command to allow live backing file change, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 23/24] block: extend block-commit to accept a string for the backing file, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 22/24] block: add helper function to determine if a BDS is in a chain, Stefan Hajnoczi, 2014/07/01
- [Qemu-devel] [PULL for-2.1 24/24] block: add backing-file option to block-stream, Stefan Hajnoczi, 2014/07/01
- Re: [Qemu-devel] [PULL for-2.1 00/24] Block patches, Peter Maydell, 2014/07/01