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

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