diff options
author | Zhiqiang Liu <liuzhiqiang26@huawei.com> | 2020-11-05 17:24:12 +0800 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2020-11-06 19:26:03 +0000 |
commit | 5670dde86ce311bfc68b0398cda545b3230787e8 (patch) | |
tree | c44977ede4200f5466d0e3127c8fd1d2386e225a /util | |
parent | 8b318a7ed691a075b89c7d095bf582af957fb075 (diff) | |
download | libfuse-5670dde86ce311bfc68b0398cda545b3230787e8.tar.gz |
mount.fuse.c: fix potential memory leak in main func
In mount.fuse.c, there are several memory leak problems in
main func. For example, setuid_name is allocated by calling
xstrdup func, however it is not freed before calling execl func.
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.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/util/mount.fuse.c b/util/mount.fuse.c index 1fc98f1..f7e60c7 100644 --- a/util/mount.fuse.c +++ b/util/mount.fuse.c @@ -233,6 +233,7 @@ int main(int argc, char *argv[]) { char *type = NULL; char *source; + char *dup_source = NULL; const char *mountpoint; char *basename; char *options = NULL; @@ -243,6 +244,7 @@ int main(int argc, char *argv[]) int suid = 1; int pass_fuse_fd = 0; int drop_privileges = 0; + char *dev_fd_mountpoint = NULL; progname = argv[0]; basename = strrchr(argv[0], '/'); @@ -340,6 +342,7 @@ int main(int argc, char *argv[]) } opt = strtok(NULL, ","); } + free(opts); } } @@ -360,7 +363,8 @@ int main(int argc, char *argv[]) if (!type) { if (source) { - type = xstrdup(source); + dup_source = xstrdup(source); + type = dup_source; source = strchr(type, '#'); if (source) *source++ = '\0'; @@ -410,7 +414,7 @@ int main(int argc, char *argv[]) if (pass_fuse_fd) { int fuse_fd = prepare_fuse_fd(mountpoint, type, options); - char *dev_fd_mountpoint = xrealloc(NULL, 20); + dev_fd_mountpoint = xrealloc(NULL, 20); snprintf(dev_fd_mountpoint, 20, "/dev/fd/%u", fuse_fd); mountpoint = dev_fd_mountpoint; } @@ -429,6 +433,11 @@ int main(int argc, char *argv[]) add_arg(&command, options); } + free(options); + free(dev_fd_mountpoint); + free(dup_source); + free(setuid_name); + execl("/bin/sh", "/bin/sh", "-c", command, NULL); fprintf(stderr, "%s: failed to execute /bin/sh: %s\n", progname, strerror(errno)); |