Whamcloud - gitweb
e2fsck: avoid memory corruption on ext2fs_open2 failure
authorNickolai Zeldovich <nickolai@csail.mit.edu>
Tue, 8 Jan 2013 20:45:31 +0000 (15:45 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 9 Jan 2013 01:42:26 +0000 (20:42 -0500)
In try_open_fs(), if ext2fs_open2() returns an error, do not try to
access the struct ext2_filesys.  The previous check 'if (ret_fs)' was
always true, but even 'if (*ret_fs)' might be incorrect in some cases,
so check 'retval==0' instead.

Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/unix.c

index 6471592..51eeb25 100644 (file)
@@ -1062,7 +1062,7 @@ static errcode_t try_open_fs(e2fsck_t ctx, int flags, io_manager io_ptr,
                retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
                                      flags, 0, 0, io_ptr, ret_fs);
 
-       if (ret_fs)
+       if (retval == 0)
                e2fsck_set_bitmap_type(*ret_fs, EXT2FS_BMAP64_RBTREE,
                                       "default", NULL);
        return retval;