From: Nickolai Zeldovich Date: Tue, 8 Jan 2013 20:45:31 +0000 (-0500) Subject: e2fsck: avoid memory corruption on ext2fs_open2 failure X-Git-Tag: v1.42.7~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a046da5963649663933cf16d54ca2a892cc1a560;p=thirdparty%2Fe2fsprogs.git e2fsck: avoid memory corruption on ext2fs_open2 failure 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 Signed-off-by: "Theodore Ts'o" --- diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 6471592ae..51eeb251b 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -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;