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 <liuzhiqiang26@huawei.com>
Signed-off-by: Haotian Li <lihaotian9@huawei.com>
This commit is contained in:
Zhiqiang Liu 2020-11-05 16:39:52 +08:00 committed by Nikolaus Rath
parent d614415a0c
commit 8b318a7ed6

View File

@ -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);