]> xenbits.xensource.com Git - qemu-xen-unstable.git/commitdiff
qcow2: Fix alloc_clusters_noref() overflow detection
authorMax Reitz <mreitz@redhat.com>
Sun, 4 May 2014 03:31:40 +0000 (05:31 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Fri, 9 May 2014 11:32:16 +0000 (13:32 +0200)
If the very first allocation has a length of 0, the free_cluster_index
is still 0 after the for loop, which means that subtracting one from it
will underflow and signal an invalid range of clusters by returning
-EFBIG. However, there is no such range, as its length is 0.

Fix this by preventing underflows on free_cluster_index during the
check.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/qcow2-refcount.c

index e79895d11dcb0b793d7eb8e4fe5e42e8714018e4..9507aef8471c3b3f93769302e35ef4c776d08556 100644 (file)
@@ -656,7 +656,9 @@ retry:
 
     /* Make sure that all offsets in the "allocated" range are representable
      * in an int64_t */
-    if (s->free_cluster_index - 1 > (INT64_MAX >> s->cluster_bits)) {
+    if (s->free_cluster_index > 0 &&
+        s->free_cluster_index - 1 > (INT64_MAX >> s->cluster_bits))
+    {
         return -EFBIG;
     }