Blame SOURCES/e2fsprogs-1.42.9-set-pointer-to-NULL-after-ext2fs_free.patch

98901c
From 68ef8adcff3acc25ddac82b808c3036b4dddaf0b Mon Sep 17 00:00:00 2001
98901c
From: Lukas Czerner <lczerner@redhat.com>
98901c
Date: Thu, 20 Feb 2014 14:14:39 +0100
98901c
Subject: [PATCH 8/8] e2fsprogs: Set pointer to NULL after ext2fs_free
98901c
98901c
ext2fs_free() does not set the ext2_filsys pointer to null so the caller
98901c
is responsible to setting it himself if it is needed.
98901c
98901c
This patch fixes some places where caller did not set ext2_filsys
98901c
pointer to NULL after ext2fs_free() which might result in use after
98901c
free. Fix it.
98901c
98901c
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
98901c
---
98901c
 lib/ext2fs/openfs.c | 7 ++++---
98901c
 resize/resize2fs.c  | 5 ++++-
98901c
 2 files changed, 8 insertions(+), 4 deletions(-)
98901c
98901c
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
98901c
index 4cdbde1..ef67493 100644
98901c
--- a/lib/ext2fs/openfs.c
98901c
+++ b/lib/ext2fs/openfs.c
98901c
@@ -419,10 +419,11 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
98901c
 
98901c
 	return 0;
98901c
 cleanup:
98901c
-	if (flags & EXT2_FLAG_NOFREE_ON_ERROR)
98901c
-		*ret_fs = fs;
98901c
-	else
98901c
+	if (!(flags & EXT2_FLAG_NOFREE_ON_ERROR)) {
98901c
 		ext2fs_free(fs);
98901c
+		fs = NULL;
98901c
+	}
98901c
+	*ret_fs = fs;
98901c
 	return retval;
98901c
 }
98901c
 
98901c
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
98901c
index 6b32bbf..a1fdefa 100644
98901c
--- a/resize/resize2fs.c
98901c
+++ b/resize/resize2fs.c
98901c
@@ -202,6 +202,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,
98901c
 	rfs->flags = flags;
98901c
 
98901c
 	ext2fs_free(rfs->old_fs);
98901c
+	rfs->old_fs = NULL;
98901c
 	if (rfs->itable_buf)
98901c
 		ext2fs_free_mem(&rfs->itable_buf);
98901c
 	if (rfs->reserve_blocks)
98901c
@@ -213,8 +214,10 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,
98901c
 	return 0;
98901c
 
98901c
 errout:
98901c
-	if (rfs->new_fs)
98901c
+	if (rfs->new_fs) {
98901c
 		ext2fs_free(rfs->new_fs);
98901c
+		rfs->new_fs = NULL;
98901c
+	}
98901c
 	if (rfs->itable_buf)
98901c
 		ext2fs_free_mem(&rfs->itable_buf);
98901c
 	ext2fs_free_mem(&rfs;;
98901c
-- 
98901c
1.8.3.1
98901c