Patchwork [PULL,20/31] qcow2: Catch bdrv_getlength() error

login
register
mail settings
Submitter Kevin Wolf
Date April 30, 2014, 6:23 p.m.
Message ID <1398882243-14783-21-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/344263/
State New
Headers show

Comments

Kevin Wolf - April 30, 2014, 6:23 p.m.
From: Max Reitz <mreitz@redhat.com>

The call to bdrv_getlength() from qcow2_check_refcounts() may result in
an error. Check this and abort if necessary.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2-refcount.c | 5 +++++
 1 file changed, 5 insertions(+)

Patch

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index d2cb6a8..e79895d 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1487,6 +1487,11 @@  int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
     int ret;
 
     size = bdrv_getlength(bs->file);
+    if (size < 0) {
+        res->check_errors++;
+        return size;
+    }
+
     nb_clusters = size_to_clusters(s, size);
     if (nb_clusters > INT_MAX) {
         res->check_errors++;