From a046da5963649663933cf16d54ca2a892cc1a560 Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Tue, 8 Jan 2013 15:45:31 -0500 Subject: [PATCH] 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" --- e2fsck/unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 6471592..51eeb25 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; -- 1.8.3.1