Whamcloud - gitweb
ext2fs_new_inode(): Add sanity check to assure a valid inode number
authorTheodore Ts'o <tytso@mit.edu>
Thu, 22 Jan 2009 20:55:49 +0000 (15:55 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 22 Jan 2009 20:55:49 +0000 (15:55 -0500)
Add a sanity check to makesure that even if the superblock field
s_first_inode is insane, that we won't return an invalid inode number.
(The function will return the error EXT2_ET_INODE_ALLOC_FAIL in that
case.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/alloc.c

index be2b56b..ade5149 100644 (file)
@@ -120,6 +120,8 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir,
        start_inode = (dir_group * EXT2_INODES_PER_GROUP(fs->super)) + 1;
        if (start_inode < EXT2_FIRST_INODE(fs->super))
                start_inode = EXT2_FIRST_INODE(fs->super);
+       if (start_inode > fs->super->s_inodes_count)
+               return EXT2_ET_INODE_ALLOC_FAIL;
        i = start_inode;
 
        do {