vmdk: Fix error handling/reporting of vmdk_check
PATCH 1/1 vmdk: Fix error handling/reporting of vmdk_check
Errors from the callees must be captured and propagated to our caller, ensure this for both find_extent() and bdrv_getlength().
Reported-by Markus Armbruster <[email protected]>
Signed-off-by Fam Zheng <[email protected]>
--- block/vmdk.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
block/vmdk.c +18 -8
@@ -2236,6 +2236,7 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result,fprintf (stderr,"ERROR: could not find extent for sector %" PRId64"\n" , sector_num); + ret = -EINVAL ;break ; } ret = get_cluster_offset(bs, extent, NULL,
@@ -2247,19 +2248,28 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result, PRId64 "\n", sector_num);break ; } -if (ret ==VMDK_OK && - cluster_offset >=bdrv_getlength (extent->file->bs)) - { -fprintf (stderr, -"ERROR: cluster offset for sector %" - PRId64" points after EOF\n" , sector_num); -break ; +if (ret ==VMDK_OK ) { +int64_t extent_len =bdrv_getlength (extent->file->bs); +if (extent_len <0 ) { +fprintf (stderr, +"ERROR: could not get extent file length for sector %" + PRId64"\n" , sector_num); + ret = extent_len; +break ; + } +if (cluster_offset >= extent_len) { +fprintf (stderr, +"ERROR: cluster offset for sector %" + PRId64" points after EOF\n" , sector_num); + ret = -EINVAL ; +break ; + } } sector_num += extent->cluster_sectors; } result->corruptions++; -return 0 ; +return ret; }static ImageInfoSpecific *vmdk_get_specific_info (BlockDriverState *bs)
Signature · 1 line
2.13.3
Quoted 10 lines · Fam Zheng
Errors from the callees must be captured and propagated to our caller, ensure this for both
find_extent()andbdrv_getlength().Reported-by Markus Armbruster <[email protected]>Signed-off-by Fam Zheng <[email protected]>--- block/vmdk.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
block/vmdk.c static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result, · line 2257
Quoted 7 lines
block/vmdk.c +7
-0+if (ret ==VMDK_OK ) { +int64_t extent_len =bdrv_getlength (extent->file->bs); +if (extent_len <0 ) { +fprintf (stderr, +"ERROR: could not get extent file length for sector %" + PRId64"\n" , sector_num); + ret = extent_len;
Pre-existing - our use of fprintf() is not ideal. But this patch doesn't make it worse.
Reviewed-by Eric Blake <[email protected]>
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Kevin Wolf
AppliedAm 04.08.2017 um 16:09 hat Fam Zheng geschrieben:
Quoted 5 lines
Errors from the callees must be captured and propagated to our caller, ensure this for both
find_extent()andbdrv_getlength().Reported-by Markus Armbruster <[email protected]>Signed-off-by Fam Zheng <[email protected]>
Thanks, applied to the block branch.
Kevin