Blame SOURCES/e2fsprogs-1.45.6-append_pathname-check-the-value-returned-by-realloc.patch

e427d2
From c74301ce5020c499445eb5c32bd70e4a1099a62d Mon Sep 17 00:00:00 2001
e427d2
From: wuguanghao <wuguanghao3@huawei.com>
e427d2
Date: Wed, 30 Jun 2021 16:27:18 +0800
e427d2
Subject: [PATCH 29/46] append_pathname: check the value returned by realloc
e427d2
Content-Type: text/plain
e427d2
e427d2
In append_pathname(), we need to add a new path to save the value
e427d2
returned by realloc, otherwise the name->path may be NULL, causing
e427d2
a segfault.
e427d2
e427d2
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
e427d2
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
e427d2
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e427d2
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
e427d2
---
e427d2
 contrib/fsstress.c | 9 ++++++++-
e427d2
 1 file changed, 8 insertions(+), 1 deletion(-)
e427d2
e427d2
diff --git a/contrib/fsstress.c b/contrib/fsstress.c
e427d2
index 2a983482..2136a903 100644
e427d2
--- a/contrib/fsstress.c
e427d2
+++ b/contrib/fsstress.c
e427d2
@@ -599,6 +599,7 @@ void add_to_flist(int ft, int id, int parent)
e427d2
 void append_pathname(pathname_t * name, char *str)
e427d2
 {
e427d2
 	int len;
e427d2
+	char *path;
e427d2
 
e427d2
 	len = strlen(str);
e427d2
 #ifdef DEBUG
e427d2
@@ -609,7 +610,13 @@ void append_pathname(pathname_t * name, char *str)
e427d2
 
e427d2
 	}
e427d2
 #endif
e427d2
-	name->path = realloc(name->path, name->len + 1 + len);
e427d2
+	path = realloc(name->path, name->len + 1 + len);
e427d2
+	if (path == NULL) {
e427d2
+		fprintf(stderr, "fsstress: append_pathname realloc failed\n");
e427d2
+		chdir(homedir);
e427d2
+		abort();
e427d2
+	}
e427d2
+	name->path = path;
e427d2
 	strcpy(&name->path[name->len], str);
e427d2
 	name->len += len;
e427d2
 }
e427d2
-- 
e427d2
2.35.1
e427d2