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 <tytso@mit.edu>
diff --git a/misc/e2image.c b/misc/e2image.c
index 99a2ed9..d52accf 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -874,8 +874,8 @@
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 @@
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)