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

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