fix
authorMiklos Szeredi <miklos@szeredi.hu>
Fri, 18 Nov 2005 21:02:36 +0000 (21:02 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Fri, 18 Nov 2005 21:02:36 +0000 (21:02 +0000)
ChangeLog
lib/mount.c
util/fusermount.c

index 51b6a19d3e97bb5f55cd5cec3d05070ac74f7a65..1d230508b84466973180ce56c359f70da5fd691b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,13 @@
 
        * More FreeBSD merge
 
+       * fusermount: don't allow mountpoints with '\n', '\t', or '\\' in
+       them, because it corrupts /etc/mtab.  Found by Thomas Biege
+
+       * libfuse: don't use system() to invoke 'fusermount -u ...'
+       because it breaks mountpoints with spaces in them into multiple
+       arguments
+
 2005-11-16  Miklos Szeredi <miklos@szeredi.hu>
 
        * Merge library part of FreeBSD port.  Patch by Csaba Henk
index 62e2b4a7476e59ed31638cd25b8d4ff2b1fddea1..787c4489d3ee57e236a455349e977104b8731a64 100644 (file)
@@ -70,13 +70,32 @@ static int receive_fd(int fd)
 void fuse_unmount(const char *mountpoint)
 {
     const char *mountprog = FUSERMOUNT_PROG;
-    char umount_cmd[1024];
+    int pid;
 
-    snprintf(umount_cmd, sizeof(umount_cmd) - 1, "%s -u -q -z -- %s",
-             mountprog, mountpoint);
+#ifdef HAVE_FORK
+    pid = fork();
+#else
+    pid = vfork();
+#endif
+    if(pid == -1)
+        return;
+
+    if(pid == 0) {
+        const char *argv[32];
+        int a = 0;
 
-    umount_cmd[sizeof(umount_cmd) - 1] = '\0';
-    system(umount_cmd);
+        argv[a++] = mountprog;
+        argv[a++] = "-u";
+        argv[a++] = "-q";
+        argv[a++] = "-z";
+        argv[a++] = "--";
+        argv[a++] = mountpoint;
+        argv[a++] = NULL;
+
+        execvp(mountprog, (char **) argv);
+        exit(1);
+    }
+    waitpid(pid, NULL, 0);
 }
 
 int fuse_mount(const char *mountpoint, const char *opts)
index 742a25f1ef8fc3e442e44d17aee92755a768774c..8d5562e93a6ad08e12f68624de9e1850650169b6 100644 (file)
@@ -120,6 +120,23 @@ static void unlock_mtab(int mtablock)
     }
 }
 
+/* Glibc addmntent() doesn't encode '\n', misencodes '\t' as '\n'
+   (version 2.3.2), and encodes '\\' differently as mount(8).  So
+   let's not allow those characters, they are not all that usual in
+   filenames. */
+static int check_name(const char *name)
+{
+    char *s;
+    for (s = "\n\t\\"; *s; s++) {
+        if (strchr(name, *s)) {
+            fprintf(stderr, "%s: illegal character 0x%02x in mount entry\n",
+                    progname, *s);
+            return -1;
+        }
+    }
+    return 0;
+}
+
 static int add_mount(const char *fsname, const char *mnt, const char *type,
                      const char *opts)
 {
@@ -128,6 +145,10 @@ static int add_mount(const char *fsname, const char *mnt, const char *type,
     struct mntent ent;
     FILE *fp;
 
+    if (check_name(fsname) == -1 || check_name(mnt) == -1 || 
+        check_name(type) == -1 || check_name(opts) == -1)
+        return -1;
+
     fp = setmntent(mtab, "a");
     if (fp == NULL) {
        fprintf(stderr, "%s: failed to open %s: %s\n", progname, mtab,