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

[PATCH 08/12] misc: fix potential segmentation fault problem in, scandir()

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

In scandir(), temp_list[num_dent] is allocated by calling
malloc(), we should check whether malloc() returns NULL before
accessing temp_list[num_dent].

Signed-off-by: Zhiqiang Liu <redacted>
Signed-off-by: Wu Guanghao <redacted>
---
 misc/create_inode.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/misc/create_inode.c b/misc/create_inode.c
index d62e1cb4..869b0614 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -771,6 +771,9 @@ static int scandir(const char *dir_name, struct dirent ***name_list,
 		}
 		// add the copy of dirent to the list
 		temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
+		if (!temp_list[num_dent]) {
+			goto out;
+		}
 		memcpy(temp_list[num_dent], dent, dent->d_reclen);
 		num_dent++;
 	}
-- 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help