Whamcloud - gitweb
Add checks for fs->blocksize == 0 which could cause some crashes
authorTheodore Ts'o <tytso@mit.edu>
Tue, 23 Feb 2021 21:02:42 +0000 (16:02 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 23 Feb 2021 21:02:42 +0000 (16:02 -0500)
This should never happeb, but some checks is useful, and also fixes
some Coverity warnings.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/do_journal.c
lib/ext2fs/csum.c
lib/ext2fs/ext2_err.et.in
lib/ext2fs/inode.c
misc/e2image.c

index a49bc36..38439c6 100644 (file)
@@ -530,8 +530,6 @@ static errcode_t journal_write(journal_t *journal,
        }
 
        err = journal_close_trans(&trans);
-       if (err)
-               goto error;
 error:
        return err;
 }
index 86184b6..da32d94 100644 (file)
@@ -263,6 +263,9 @@ static errcode_t __get_dirent_tail(ext2_filsys fs,
        errcode_t retval = 0;
        __u16 (*translate)(__u16) = (need_swab ? disk_to_host16 : do_nothing16);
 
+       if (fs->blocksize < 1024)
+               return EXT2_FILSYS_CORRUPTED; /* Should never happen */
+
        d = dirent;
        top = EXT2_DIRENT_TAIL(dirent, fs->blocksize);
 
index 0c76fee..cf0e00e 100644 (file)
@@ -548,4 +548,7 @@ ec  EXT2_ET_EA_INODE_CORRUPTED,
 ec     EXT2_ET_NO_GDESC,
        "Group descriptors not loaded"
 
+ec     EXT2_FILSYS_CORRUPTED,
+       "The internal ext2_filsys data structure appears to be corrupted"
+
        end
index c4377ee..6f42882 100644 (file)
@@ -144,6 +144,8 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
        errcode_t (*save_get_blocks)(ext2_filsys f, ext2_ino_t ino, blk_t *blocks);
 
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
+       if (fs->blocksize < 1024)
+               return EXT2_FILSYS_CORRUPTED; /* Should never happen */
 
        /*
         * If fs->badblocks isn't set, then set it --- since the inode
@@ -764,6 +766,8 @@ errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
        int             cache_slot, fail_csum;
 
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
+       if (fs->blocksize < 1024)
+               return EXT2_FILSYS_CORRUPTED; /* Should never happen */
 
        /* Check to see if user has an override function */
        if (fs->read_inode &&
index 90a34be..347759b 100644 (file)
@@ -897,8 +897,9 @@ static errcode_t 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... */
+       /* Sbould never happen, but just in case... */
+       if (cluster_bits < 0)
+               return EXT2_FILSYS_CORRUPTED;
 
        /* Allocate header */
        ret = ext2fs_get_memzero(sizeof(struct ext2_qcow2_hdr), &header);