]> git.proxmox.com Git - mirror_qemu.git/commit
block: Guarantee that *file is set on bdrv_get_block_status()
authorEric Blake <eblake@redhat.com>
Mon, 5 Jun 2017 20:38:43 +0000 (15:38 -0500)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Thu, 3 Aug 2017 21:01:28 +0000 (16:01 -0500)
commit64945cb5f35f6b52ddc5ef0e4396b93d5bf87e1e
tree1c62d7c1ce6240a8da800082914bf0ca5edab0d0
parent6a3f9c5c6e54d05e35bad786ce619d72d02c29de
block: Guarantee that *file is set on bdrv_get_block_status()

We document that *file is valid if the return is not an error and
includes BDRV_BLOCK_OFFSET_VALID, but forgot to obey this contract
when a driver (such as blkdebug) lacks a callback.  Messed up in
commit 67a0fd2 (v2.6), when we added the file parameter.

Enhance qemu-iotest 177 to cover this, using a sequence that would
print garbage or even SEGV, because it was dererefencing through
uninitialized memory.  [The resulting test output shows that we
have less-than-ideal block status from the blkdebug driver, but
that's a separate fix coming up soon.]

Setting *file on all paths that return BDRV_BLOCK_OFFSET_VALID is
enough to fix the crash, but we can go one step further: always
setting *file, even on error, means that a broken caller that
blindly dereferences file without checking for error is now more
likely to get a reliable SEGV instead of randomly acting on garbage,
making it easier to diagnose such buggy callers.  Adding an
assertion that file is set where expected doesn't hurt either.

CC: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 81c219ac6ce0d6182e35f3976f2caa4cefcaf9f0)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
block/io.c
tests/qemu-iotests/177
tests/qemu-iotests/177.out