From: Zhiqiang Liu Date: Wed, 30 Jun 2021 08:27:20 +0000 (+0800) Subject: misc: fix potential segmentation fault problem in scandir() X-Git-Tag: v1.46.3~18 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=f9033bd2e82c6f5963034cd59f7273770374b598;p=tools%2Fe2fsprogs.git misc: fix potential segmentation fault problem in scandir() 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 Signed-off-by: Wu Guanghao Signed-off-by: Theodore Ts'o --- diff --git a/misc/create_inode.c b/misc/create_inode.c index d62e1cb..c00d545 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -771,6 +771,8 @@ 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++; }