aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorZhiqiang Liu <liuzhiqiang26@huawei.com>2020-11-05 16:39:52 +0800
committerNikolaus Rath <Nikolaus@rath.org>2020-11-06 19:26:03 +0000
commit8b318a7ed691a075b89c7d095bf582af957fb075 (patch)
tree3cc46395d67760ef0ee19d0620074342269be604 /util
parentd614415a0c4ebf587e690ea209da1436e73fae19 (diff)
downloadlibfuse-8b318a7ed691a075b89c7d095bf582af957fb075.tar.gz
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>
Diffstat (limited to 'util')
-rw-r--r--util/mount.fuse.c2
1 files changed, 1 insertions, 1 deletions
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);