Blame SOURCES/e2fsprogs-1.45.6-lsattr-check-whether-path-is-NULL-in-lsattr_dir_proc.patch

f239de
From 18850fa92c398f4a60827dd5da020f9af0822424 Mon Sep 17 00:00:00 2001
f239de
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
f239de
Date: Wed, 28 Jul 2021 09:56:48 +0800
f239de
Subject: [PATCH 37/46] lsattr: check whether path is NULL in lsattr_dir_proc()
f239de
Content-Type: text/plain
f239de
f239de
In lsattr_dir_proc(), if malloc() return NULL, it will cause
f239de
a segmentation fault problem.
f239de
f239de
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
f239de
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
f239de
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
f239de
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
f239de
---
f239de
 misc/lsattr.c | 5 +++++
f239de
 1 file changed, 5 insertions(+)
f239de
f239de
diff --git a/misc/lsattr.c b/misc/lsattr.c
f239de
index 0d954376..55080e92 100644
f239de
--- a/misc/lsattr.c
f239de
+++ b/misc/lsattr.c
f239de
@@ -144,6 +144,11 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
f239de
 	int dir_len = strlen(dir_name);
f239de
 
f239de
 	path = malloc(dir_len + strlen (de->d_name) + 2);
f239de
+	if (!path) {
f239de
+		fputs(_("Couldn't allocate path variable in lsattr_dir_proc\n"),
f239de
+			stderr);
f239de
+		return -1;
f239de
+	}
f239de
 
f239de
 	if (dir_len && dir_name[dir_len-1] == '/')
f239de
 		sprintf (path, "%s%s", dir_name, de->d_name);
f239de
-- 
f239de
2.35.1
f239de