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

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