]> git.proxmox.com Git - mirror_qemu.git/commit - block/qcow2-cluster.c
qcow2: Check min_size in qcow2_grow_l1_table()
authorMax Reitz <mreitz@redhat.com>
Tue, 29 Apr 2014 17:03:14 +0000 (19:03 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 30 Apr 2014 12:46:17 +0000 (14:46 +0200)
commitb93f995081cc32e56071fef179161d2907d0491e
treec4a4a5ab3111109055ffac05634c2d298b44b4e9
parenta49139af77850d64d74f9ffe43cabe7aa4f19de0
qcow2: Check min_size in qcow2_grow_l1_table()

First, new_l1_size is an int64_t, whereas min_size is a uint64_t.
Therefore, during the loop which adjusts new_l1_size until it equals or
exceeds min_size, new_l1_size might overflow and become negative. The
comparison in the loop condition however will take it as an unsigned
value (because min_size is unsigned) and therefore recognize it as
exceeding min_size. Therefore, the loop is left with a negative
new_l1_size, which is not correct. This could be fixed by making
new_l1_size uint64_t.

On the other hand, however, by doing this, the while loop may take
forever. If min_size is e.g. UINT64_MAX, it will take new_l1_size
probably multiple overflows to reach the exact same value (if it reaches
it at all). Then, right after the loop, new_l1_size will be recognized
as being too big anyway.

Both problems require a ridiculously high min_size value, which is very
unlikely to occur; but both problems are also simply avoided by checking
whether min_size is sane before calculating new_l1_size (which should
still be checked separately, though).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/qcow2-cluster.c