From fdbec203bb2483e4533e62ef5c2dd0cc66f09234 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Fri, 28 May 2010 12:21:27 +0200 Subject: qcow2: Fix corruption after error in update_refcount After it is done with updating refcounts in the cache, update_refcount writes all changed entries to disk. If a refcount block allocation fails, however, there was no change yet and therefore first_index = last_index = -1. Don't treat -1 as a normal sector index (resulting in a 512 byte write!) but return without updating anything in this case. Signed-off-by: Kevin Wolf (cherry picked from commit 86fa8da83771238de55dc44819a1a27bafef5353) --- block/qcow2-refcount.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'block') diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index fa78e46ee..465d5d36e 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -402,6 +402,10 @@ static int write_refcount_block_entries(BDRVQcowState *s, return 0; } + if (first_index < 0) { + return 0; + } + first_index &= ~(REFCOUNTS_PER_SECTOR - 1); last_index = (last_index + REFCOUNTS_PER_SECTOR) & ~(REFCOUNTS_PER_SECTOR - 1); -- cgit v1.2.3-65-gdbad