diff mbox

block: Check bdrv_getlength() return value in bdrv_append_temp_snapshot()

Message ID 1396624153-7461-1-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf April 4, 2014, 3:09 p.m. UTC
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Max Reitz April 4, 2014, 3:23 p.m. UTC | #1
On 04.04.2014 17:09, Kevin Wolf wrote:
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>   block.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index d89c344..990a754 100644
--- a/block.c
+++ b/block.c
@@ -1184,7 +1184,12 @@  void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp)
        instead of opening 'filename' directly */
 
     /* Get the required size from the image */
-    total_size = bdrv_getlength(bs) & BDRV_SECTOR_MASK;
+    total_size = bdrv_getlength(bs);
+    if (total_size < 0) {
+        error_setg_errno(errp, -total_size, "Could not get image size");
+        return;
+    }
+    total_size &= BDRV_SECTOR_MASK;
 
     /* Create the temporary image */
     ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));