Whamcloud - gitweb
e2image: Add an assertion/sanity check in initialize_qcow2_image()
authorTheodore Ts'o <tytso@mit.edu>
Sun, 24 Jun 2018 05:04:48 +0000 (01:04 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 24 Jun 2018 05:04:48 +0000 (01:04 -0400)
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>
misc/e2image.c

index 99a2ed9..d52accf 100644 (file)
@@ -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)