[Debian-ha-commits] [ocfs2-tools] 25/58: mkfs.ocfs2: fix a potential segment fault in main()

Valentin Vidic vvidic-guest at moszumanska.debian.org
Tue Jun 20 13:40:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

vvidic-guest pushed a commit to branch upstream
in repository ocfs2-tools.

commit edda9d558ba10b256a5a5642360b8669cb04728e
Author: Jun Piao <piaojun at huawei.com>
Date:   Thu Sep 22 21:52:23 2016 +0800

    mkfs.ocfs2: fix a potential segment fault in main()
    
    's->global_bm' may be NULL in free_state() as 's->global_bm' will be
    initialized later by initialize_bitmap(). So we need judge 'global_bm'
    before access its members. The same problem happens for 'system_group'.
    
    'State *s' need to be free in free_state() in case of memory leak.
    
    Fixes: cec294ef135c ("mkfs.ocfs2: fix memory leak problems in main()")
    
    Signed-off-by: Jun Piao <piaojun at huawei.com>
    Reviewed-by: Joseph Qi <joseph.qi at huawei.com>
---
 mkfs.ocfs2/mkfs.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index 8532e12..0997d5b 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -1251,13 +1251,16 @@ free_state(State *s)
 	ocfs2_free(&s->cluster_stack);
 	ocfs2_free(&s->cluster_name);
 
-	for (i = 0; i < s->nr_cluster_groups; i++)
-		free_alloc_group(s->global_bm->groups[i]);
-	ocfs2_free(&s->global_bm->groups);
-	ocfs2_free(&s->global_bm->name);
-	ocfs2_free(&s->global_bm);
+	if (s->global_bm) {
+		for (i = 0; i < s->nr_cluster_groups; i++)
+			free_alloc_group(s->global_bm->groups[i]);
+		ocfs2_free(&s->global_bm->groups);
+		ocfs2_free(&s->global_bm->name);
+		ocfs2_free(&s->global_bm);
+	}
 
 	free_alloc_group(s->system_group);
+	ocfs2_free(&s);
 }
 
 static int
@@ -1877,9 +1880,11 @@ initialize_alloc_group(State *s, const char *name,
 static void
 free_alloc_group(AllocGroup *group)
 {
-	ocfs2_free(&group->name);
-	ocfs2_free(&group->gd);
-	ocfs2_free(&group);
+	if (group) {
+		ocfs2_free(&group->name);
+		ocfs2_free(&group->gd);
+		ocfs2_free(&group);
+	}
 }
 
 static AllocBitmap *

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-ha/ocfs2-tools.git



More information about the Debian-HA-Commits mailing list