From: Zhiqiang Liu Date: Thu, 5 Nov 2020 08:39:52 +0000 (+0800) Subject: mount.fuse.c: fix potential accessing NULL pointer X-Git-Tag: fuse-3.10.1~8 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=8b318a7ed691a075b89c7d095bf582af957fb075;p=qemu-gpiodev%2Flibfuse.git 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 --- 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);