Whamcloud - gitweb
misc: fix potential segmentation fault problem in scandir()
authorZhiqiang Liu <liuzhiqiang26@huawei.com>
Wed, 30 Jun 2021 08:27:20 +0000 (16:27 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 16 Jul 2021 03:43:37 +0000 (23:43 -0400)
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 <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/create_inode.c

index d62e1cb..c00d545 100644 (file)
@@ -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++;
        }