From: Zhiqiang Liu Date: Wed, 28 Jul 2021 01:56:48 +0000 (+0800) Subject: lsattr: check whether path is NULL in lsattr_dir_proc() X-Git-Tag: v1.46.4~45 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=c8e9e0135b3eb0d8a18387d58645e7cc1062da58;p=tools%2Fe2fsprogs.git lsattr: check whether path is NULL in lsattr_dir_proc() In lsattr_dir_proc(), if malloc() return NULL, it will cause a segmentation fault problem. Signed-off-by: Zhiqiang Liu Signed-off-by: Wu Guanghao Signed-off-by: Theodore Ts'o --- diff --git a/misc/lsattr.c b/misc/lsattr.c index 0d95437..55080e9 100644 --- a/misc/lsattr.c +++ b/misc/lsattr.c @@ -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);