|
|
e427d2 |
From 4a92545b8711df405dc804236d66386780696ce1 Mon Sep 17 00:00:00 2001
|
|
|
e427d2 |
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
|
|
|
e427d2 |
Date: Wed, 30 Jun 2021 16:27:20 +0800
|
|
|
e427d2 |
Subject: [PATCH 31/46] misc: fix potential segmentation fault problem in
|
|
|
e427d2 |
scandir()
|
|
|
e427d2 |
Content-Type: text/plain
|
|
|
e427d2 |
|
|
|
e427d2 |
In scandir(), temp_list[num_dent] is allocated by calling
|
|
|
e427d2 |
malloc(), we should check whether malloc() returns NULL before
|
|
|
e427d2 |
accessing temp_list[num_dent].
|
|
|
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/create_inode.c | 2 ++
|
|
|
e427d2 |
1 file changed, 2 insertions(+)
|
|
|
e427d2 |
|
|
|
e427d2 |
diff --git a/misc/create_inode.c b/misc/create_inode.c
|
|
|
e427d2 |
index 6f8487b9..38f37beb 100644
|
|
|
e427d2 |
--- a/misc/create_inode.c
|
|
|
e427d2 |
+++ b/misc/create_inode.c
|
|
|
e427d2 |
@@ -752,6 +752,8 @@ static int scandir(const char *dir_name, struct dirent ***name_list,
|
|
|
e427d2 |
}
|
|
|
e427d2 |
// add the copy of dirent to the list
|
|
|
e427d2 |
temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
|
|
|
e427d2 |
+ if (!temp_list[num_dent])
|
|
|
e427d2 |
+ goto out;
|
|
|
e427d2 |
memcpy(temp_list[num_dent], dent, dent->d_reclen);
|
|
|
e427d2 |
num_dent++;
|
|
|
e427d2 |
}
|
|
|
e427d2 |
--
|
|
|
e427d2 |
2.35.1
|
|
|
e427d2 |
|