Thread (20 messages) 20 messages, 3 authors, 2021-05-29
STALE1839d

[PATCH 11/12] misc/lsattr: check whether path is NULL in, lsattr_dir_proc()

From: Wu Guanghao <hidden>
Date: 2021-05-24 11:25:59
Subsystem: the rest · Maintainer: Linus Torvalds

In lsattr_dir_proc(), if malloc() return NULL, it will cause
a segmentation fault problem.

Signed-off-by: Zhiqiang Liu <redacted>
Signed-off-by: Wu Guanghao <redacted>
---
 misc/lsattr.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/misc/lsattr.c b/misc/lsattr.c
index 0d954376..f3212069 100644
--- a/misc/lsattr.c
+++ b/misc/lsattr.c
@@ -144,6 +144,12 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
 	int dir_len = strlen(dir_name);

 	path = malloc(dir_len + strlen (de->d_name) + 2);
+	if (!path) {
+		fprintf(stderr, "%s",
+			_("Couldn't allocate path variable "
+			  "in lsattr_dir_proc"));
+		return -1;
+	}

 	if (dir_len && dir_name[dir_len-1] == '/')
 		sprintf (path, "%s%s", dir_name, de->d_name);
-- 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help