diff options
author | Eric Blake <eblake@redhat.com> | 2017-08-09 15:38:08 -0500 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-08-11 13:23:47 +0200 |
commit | d0d5d0e31a874d592741a088c2c5071bae164dbf (patch) | |
tree | 83537d17c9bdaedabe85ff61d645adb85718e650 /block/qcow2.c | |
parent | c40fe9c06c35fa8076f9a0daeea5c8684d773645 (diff) |
qcow2: Check failure of bdrv_getlength()
qcow2_co_pwritev_compressed() should not call bdrv_truncate()
if determining the size failed.
Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r-- | block/qcow2.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index 99407403ea..40ba26c111 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3282,12 +3282,15 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, z_stream strm; int ret, out_len; uint8_t *buf, *out_buf; - uint64_t cluster_offset; + int64_t cluster_offset; if (bytes == 0) { /* align end of file to a sector boundary to ease reading with sector based I/Os */ cluster_offset = bdrv_getlength(bs->file->bs); + if (cluster_offset < 0) { + return cluster_offset; + } return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL); } |