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

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