From: Theodore Ts'o Date: Sun, 24 Jun 2018 05:04:48 +0000 (-0400) Subject: e2image: Add an assertion/sanity check in initialize_qcow2_image() X-Git-Tag: v1.44.3-rc1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4a0742a07feffcf0648cd689e8458ff189fd4a6;p=thirdparty%2Fe2fsprogs.git e2image: Add an assertion/sanity check in initialize_qcow2_image() This is mostly to shut up some coverity warnings, but in theory fs->blocksize could have been corrupted outside of this function... Fixes-Coverity-Bug: 1297492 Fixes-Coverity-Bug: 1297490 Fixes-Coverity-Bug: 1297488 Signed-off-by: Theodore Ts'o --- diff --git a/misc/e2image.c b/misc/e2image.c index 99a2ed9eb..d52accf5d 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -874,8 +874,8 @@ static int init_refcount(struct ext2_qcow2_image *img, blk64_t table_offset) return ret; } -static int initialize_qcow2_image(int fd, ext2_filsys fs, - struct ext2_qcow2_image *image) +static errcode_t initialize_qcow2_image(int fd, ext2_filsys fs, + struct ext2_qcow2_image *image) { struct ext2_qcow2_hdr *header; blk64_t total_size, offset; @@ -883,6 +883,9 @@ static int initialize_qcow2_image(int fd, ext2_filsys fs, int cluster_bits = get_bits_from_size(fs->blocksize); struct ext2_super_block *sb = fs->super; + if (fs->blocksize < 1024) + return EINVAL; /* Can never happen, but just in case... */ + /* Allocate header */ ret = ext2fs_get_memzero(sizeof(struct ext2_qcow2_hdr), &header); if (ret)