Whamcloud - gitweb
libext2fs: Fix a corner case bug in ext2fs_unlink
authorTheodore Ts'o <tytso@mit.edu>
Sat, 1 Dec 2007 12:08:45 +0000 (07:08 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 2 Dec 2007 10:25:30 +0000 (05:25 -0500)
We cannot merge a removed directory entry to just arbitrary previous
directory entry. The previous entry must be in the same block.  So
really bad things can happen when are deleting the first directory
entry in a block where the last directory entry in the previous
directory block is not in use.  We fix this bug by checking to see if
the current entry is not the first one in the block before trying to
merge it to the previous entry.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/unlink.c

index e7b2182..a48b877 100644 (file)
@@ -31,7 +31,7 @@ struct link_struct  {
  #pragma argsused
 #endif
 static int unlink_proc(struct ext2_dir_entry *dirent,
-                    int        offset EXT2FS_ATTR((unused)),
+                    int        offset,
                     int        blocksize EXT2FS_ATTR((unused)),
                     char       *buf EXT2FS_ATTR((unused)),
                     void       *priv_data)
@@ -56,7 +56,7 @@ static int unlink_proc(struct ext2_dir_entry *dirent,
                        return 0;
        }
 
-       if (prev) 
+       if (offset)
                prev->rec_len += dirent->rec_len;
        else
                dirent->inode = 0;