]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: don't generate empty option strings
authorKarel Zak <kzak@redhat.com>
Thu, 14 Jun 2012 09:38:53 +0000 (11:38 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 14 Jun 2012 09:38:53 +0000 (11:38 +0200)
 mount -t foo something /mnt/test -o user=root,password=linux

generates

 "rw,noexec,nosuid,nodev,password=linux,,user=root"

options string for /sbin/mount.foo, the ",," is incorrect.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c
libmount/src/optstr.c

index 264276899600baad3e262671cf956e7ad40a56a8..6661394ffcdbb50809bd6ce8300df9b304090012 100644 (file)
@@ -67,16 +67,27 @@ static int fix_optstr(struct libmnt_context *cxt)
        /*
         * Sync mount options with mount flags
         */
+       DBG(CXT, mnt_debug_h(cxt, "mount: fixing vfs optstr"));
        rc = mnt_optstr_apply_flags(&fs->vfs_optstr, cxt->mountflags,
                                mnt_get_builtin_optmap(MNT_LINUX_MAP));
        if (rc)
                goto done;
 
+       DBG(CXT, mnt_debug_h(cxt, "mount: fixing user optstr"));
        rc = mnt_optstr_apply_flags(&fs->user_optstr, cxt->user_mountflags,
                                mnt_get_builtin_optmap(MNT_USERSPACE_MAP));
        if (rc)
                goto done;
 
+       if (fs->vfs_optstr && *fs->vfs_optstr == '\0') {
+               free(fs->vfs_optstr);
+               fs->vfs_optstr = NULL;
+       }
+       if (fs->user_optstr && *fs->user_optstr == '\0') {
+               free(fs->user_optstr);
+               fs->user_optstr = NULL;
+       }
+
        next = fs->fs_optstr;
 
 #ifdef HAVE_LIBSELINUX
index 66d2a06c39263a9a0b261883266623102167402d..ca1b2e2c7ff3a63dad4098d3fa6d2e725ab8ec49 100644 (file)
@@ -174,6 +174,8 @@ static int __mnt_optstr_append_option(char **optstr,
        size_t sz, osz;
 
        assert(name);
+       assert(*name);
+       assert(nsz);
 
        osz = *optstr ? strlen(*optstr) : 0;
 
@@ -219,7 +221,7 @@ int mnt_optstr_append_option(char **optstr, const char *name, const char *value)
 {
        size_t vsz, nsz;
 
-       if (!name)
+       if (!name || !*name)
                return 0;
 
        nsz = strlen(name);