Whamcloud - gitweb
lsattr: check whether path is NULL in lsattr_dir_proc()
authorZhiqiang Liu <liuzhiqiang26@huawei.com>
Wed, 28 Jul 2021 01:56:48 +0000 (09:56 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 3 Aug 2021 02:35:02 +0000 (22:35 -0400)
In lsattr_dir_proc(), if malloc() return NULL, it will cause
a segmentation fault problem.

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/lsattr.c

index 0d95437..55080e9 100644 (file)
@@ -144,6 +144,11 @@ 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) {
+               fputs(_("Couldn't allocate path variable in lsattr_dir_proc\n"),
+                       stderr);
+               return -1;
+       }
 
        if (dir_len && dir_name[dir_len-1] == '/')
                sprintf (path, "%s%s", dir_name, de->d_name);