diff mbox series

[v3,11/12] misc/lsattr: check whether path is NULL in lsattr_dir_proc()

Message ID 20210728015648.284588-5-wuguanghao3@huawei.com
State Accepted
Headers show
Series e2fsprogs: some bugfixs | expand

Commit Message

wuguanghao July 28, 2021, 1:56 a.m. UTC
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>

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>
---
 misc/lsattr.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Theodore Ts'o Aug. 3, 2021, 2:35 a.m. UTC | #1
On Wed, Jul 28, 2021 at 09:56:48AM +0800, wuguanghao wrote:
> From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> 
> 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>

Thanks, applied.

Note that fputs() does not print a trailing newline (unlike puts()).
So I fixed up the error message to include a newline character at the
end.

				- Ted
diff mbox series

Patch

diff --git a/misc/lsattr.c b/misc/lsattr.c
index 0d954376..7958f0ad 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"),
+			stderr);
+		return -1;
+	}
 
 	if (dir_len && dir_name[dir_len-1] == '/')
 		sprintf (path, "%s%s", dir_name, de->d_name);