summaryrefslogtreecommitdiff
path: root/lib/mount_util.c
diff options
context:
space:
mode:
authorAlex Richman <alex@richman.io>2016-07-21 16:17:40 +0100
committerNikolaus Rath <Nikolaus@rath.org>2016-07-21 17:17:40 +0200
commit1bec2c1a54a4904af6eb5faf6fdb09cdceacc6b9 (patch)
treee0b20006a955dc5c1f089821d02919ada97eff3c /lib/mount_util.c
parent81370fcdc2afbac21f8ba4a6aaf37c46304cbca2 (diff)
downloadfuse-1bec2c1a54a4904af6eb5faf6fdb09cdceacc6b9.tar.gz
add error checking to setuid calls (#66)
Diffstat (limited to 'lib/mount_util.c')
-rw-r--r--lib/mount_util.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/mount_util.c b/lib/mount_util.c
index 589f76d..ad9d38c 100644
--- a/lib/mount_util.c
+++ b/lib/mount_util.c
@@ -100,7 +100,13 @@ static int add_mount(const char *progname, const char *fsname,
char *env = NULL;
sigprocmask(SIG_SETMASK, &oldmask, NULL);
- setuid(geteuid());
+
+ if(setuid(geteuid()) == -1) {
+ fprintf(stderr, "%s: setuid: %s\n", progname, strerror(errno));
+ res = -1;
+ goto out_restore;
+ }
+
execle("/bin/mount", "/bin/mount", "--no-canonicalize", "-i",
"-f", "-t", type, "-o", opts, fsname, mnt, NULL, &env);
fprintf(stderr, "%s: failed to execute /bin/mount: %s\n",
@@ -153,7 +159,13 @@ static int exec_umount(const char *progname, const char *rel_mnt, int lazy)
char *env = NULL;
sigprocmask(SIG_SETMASK, &oldmask, NULL);
- setuid(geteuid());
+
+ if(setuid(geteuid()) == -1) {
+ fprintf(stderr, "%s: setuid: %s\n", progname, strerror(errno));
+ res = -1;
+ goto out_restore;
+ }
+
if (lazy) {
execle("/bin/umount", "/bin/umount", "-i", rel_mnt,
"-l", NULL, &env);
@@ -219,7 +231,13 @@ static int remove_mount(const char *progname, const char *mnt)
char *env = NULL;
sigprocmask(SIG_SETMASK, &oldmask, NULL);
- setuid(geteuid());
+
+ if(setuid(geteuid()) == -1) {
+ fprintf(stderr, "%s: setuid: %s\n", progname, strerror(errno));
+ res = -1;
+ goto out_restore;
+ }
+
execle("/bin/umount", "/bin/umount", "--no-canonicalize", "-i",
"--fake", mnt, NULL, &env);
fprintf(stderr, "%s: failed to execute /bin/umount: %s\n",