aboutsummaryrefslogtreecommitdiff
path: root/block/vmdk.c
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2017-08-04 22:09:42 +0800
committerKevin Wolf <kwolf@redhat.com>2017-08-08 15:19:16 +0200
commit0e51b9b7c7b24127e9996259b611db3177ef6444 (patch)
tree3b19d5c651ad26eed2bdb0f118d43662ce158442 /block/vmdk.c
parent809eb70ed6cfbfb6c198a25aed036849cc11944d (diff)
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 <armbru@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vmdk.c')
-rw-r--r--block/vmdk.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/block/vmdk.c b/block/vmdk.c
index 0fc97391a6..c665bcc977 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -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)