diff mbox

raw: Fix segfault in raw_create when opts is NULL

Message ID 1403134317-6817-1-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng June 18, 2014, 11:31 p.m. UTC
Reported-by: Milos Vyletel <milos.vyletel@gmail.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/raw-posix.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Eric Blake June 19, 2014, 12:14 a.m. UTC | #1
On 06/18/2014 05:31 PM, Fam Zheng wrote:
> Reported-by: Milos Vyletel <milos.vyletel@gmail.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/raw-posix.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 

Chunyan's solution looks better:
https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg04104.html
diff mbox

Patch

diff --git a/block/raw-posix.c b/block/raw-posix.c
index dacf4fb..1f45fd8 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1282,8 +1282,10 @@  static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
     strstart(filename, "file:", &filename);
 
     /* Read out options */
-    total_size =
-        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+    if (opts) {
+        total_size =
+            qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+    }
 
     fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
                    0644);