Skip to content

Commit

Permalink
parallels: return earlier from parallels_open() function on error
Browse files Browse the repository at this point in the history
At the beginning of the function we can return immediately until we
really allocate s->header.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
  • Loading branch information
Denis V. Lunev committed Sep 20, 2023
1 parent d6353f0 commit c30756f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions block/parallels.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,

ret = bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0);
if (ret < 0) {
goto fail;
return ret;
}

bs->total_sectors = le64_to_cpu(ph.nb_sectors);
Expand All @@ -1110,30 +1110,26 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
s->tracks = le32_to_cpu(ph.tracks);
if (s->tracks == 0) {
error_setg(errp, "Invalid image: Zero sectors per track");
ret = -EINVAL;
goto fail;
return -EINVAL;
}
if (s->tracks > INT32_MAX/513) {
error_setg(errp, "Invalid image: Too big cluster");
ret = -EFBIG;
goto fail;
return -EFBIG;
}
s->prealloc_size = MAX(s->tracks, s->prealloc_size);
s->cluster_size = s->tracks << BDRV_SECTOR_BITS;

s->bat_size = le32_to_cpu(ph.bat_entries);
if (s->bat_size > INT_MAX / sizeof(uint32_t)) {
error_setg(errp, "Catalog too large");
ret = -EFBIG;
goto fail;
return -EFBIG;
}

size = bat_entry_off(s->bat_size);
s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file->bs));
s->header = qemu_try_blockalign(bs->file->bs, s->header_size);
if (s->header == NULL) {
ret = -ENOMEM;
goto fail;
return -ENOMEM;
}

ret = bdrv_pread(bs->file, 0, s->header_size, s->header, 0);
Expand Down

0 comments on commit c30756f

Please sign in to comment.