From 8b318a7ed691a075b89c7d095bf582af957fb075 Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Thu, 5 Nov 2020 16:39:52 +0800 Subject: [PATCH] mount.fuse.c: fix potential accessing NULL pointer In mount.fuse.c, pwd is set by calling getpwnam func. If the matching entry is not found or an error occurs in getpwnam func, pwd will be NULL. So we need to check whether pwd is NULL before accessing it. Signed-off-by: Zhiqiang Liu Signed-off-by: Haotian Li --- util/mount.fuse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/mount.fuse.c b/util/mount.fuse.c index dc59c9d..1fc98f1 100644 --- a/util/mount.fuse.c +++ b/util/mount.fuse.c @@ -398,7 +398,7 @@ int main(int argc, char *argv[]) #endif struct passwd *pwd = getpwnam(setuid_name); - if (setgid(pwd->pw_gid) == -1 || setuid(pwd->pw_uid) == -1) { + if (!pwd || setgid(pwd->pw_gid) == -1 || setuid(pwd->pw_uid) == -1) { fprintf(stderr, "%s: Failed to setuid to %s: %s\n", progname, setuid_name, strerror(errno)); exit(1); -- 2.30.2