From: Karel Zak Date: Thu, 14 Jun 2012 09:38:53 +0000 (+0200) Subject: libmount: don't generate empty option strings X-Git-Tag: v2.22-rc1~288 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b741564d84ee21573b3ebff5510f6b050028d06;p=thirdparty%2Futil-linux.git libmount: don't generate empty option strings 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 --- diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 2642768996..6661394ffc 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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 diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index 66d2a06c39..ca1b2e2c7f 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -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);