]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: make sure "option=" is used as string
authorKarel Zak <kzak@redhat.com>
Wed, 20 Mar 2024 15:08:16 +0000 (16:08 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 20 Mar 2024 15:08:16 +0000 (16:08 +0100)
mount(8) cares about case when option specified as "name=" (it means
without data). See for example 727c689908c5e68c92aa1dd65e0d3bdb6d91c1e5.

We need this also for new mount API and use FSCONFIG_SET_STRING rather
than FSCONFIG_SET_FLAG.

strace -e fsconfig ./mount -o usrjquota= /dev/sdc1 /mnt/test

Old:
fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sdc1", 0) = 0
fsconfig(3, FSCONFIG_SET_FLAG, "usrjquota", NULL, 0) = -1 EINVAL (Invalid argument)

Fixed:
fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sdc1", 0) = 0
fsconfig(3, FSCONFIG_SET_STRING, "usrjquota", "", 0) = 0

Fixes: https://github.com/util-linux/util-linux/issues/2837
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/hook_mount.c
libmount/src/mountP.h
libmount/src/optlist.c

index 92438966c0e1a09e11dd1c53fe4a42c3eceb5815..f0cc381963dba1dbdabe9b5887b9877e8035adb9 100644 (file)
@@ -224,6 +224,9 @@ static int configure_superblock(struct libmnt_context *cxt,
                        /* Ignore VFS flags, userspace and external options */
                        continue;
 
+               if (!value && mnt_opt_is_sepnodata(opt))
+                       value = "";     /* force use the value as string */
+
                rc = fsconfig_set_value(cxt, hs, fd, name, value);
                if (rc != 0)
                        goto done;
index 458aa1a00d02d0c40b35aea5db68899a3f8bc9a2..fcc40bffc599dd904ddd737edac465223a12817d 100644 (file)
@@ -608,6 +608,7 @@ extern int mnt_opt_set_value(struct libmnt_opt *opt, const char *str);
 extern int mnt_opt_set_u64value(struct libmnt_opt *opt, uint64_t num);
 extern int mnt_opt_set_quoted_value(struct libmnt_opt *opt, const char *str);
 extern int mnt_opt_is_external(struct libmnt_opt *opt);
+extern int mnt_opt_is_sepnodata(struct libmnt_opt *opt);
 
 /* fs.c */
 extern int mnt_fs_follow_optlist(struct libmnt_fs *fs, struct libmnt_optlist *ol);
index 101c908aeff3b7a002daf34e446acfd4c9333042..476acfd656f14b0103b87c380438f605be403517 100644 (file)
@@ -46,6 +46,7 @@ struct libmnt_opt {
 
        unsigned int external : 1,      /* visible for external helpers only */
                     recursive : 1,     /* recursive flag */
+                    sepnodata : 1,     /* value separator, but without data ("name=") */
                     is_linux : 1,      /* defined in ls->linux_map (VFS attr) */
                     quoted : 1;        /* name="value" */
 };
@@ -438,6 +439,10 @@ static struct libmnt_opt *optlist_new_opt(struct libmnt_optlist *ls,
                opt->value = strndup(value, valsz);
                if (!opt->value)
                        goto fail;
+
+       } else if (value) {
+               /* separator specified, but empty value ("name=") */
+               opt->sepnodata = 1;
        }
        if (namesz) {
                opt->name = strndup(name, namesz);
@@ -957,7 +962,8 @@ int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr,
                        continue;
                rc = mnt_buffer_append_option(&buf,
                                        opt->name, strlen(opt->name),
-                                       opt->value,
+                                       opt->value ? opt->value :
+                                                    opt->sepnodata ? "" : NULL,
                                        opt->value ? strlen(opt->value) : 0,
                                        opt->quoted);
                if (rc)
@@ -1043,6 +1049,7 @@ struct libmnt_optlist *mnt_copy_optlist(struct libmnt_optlist *ls)
                        no->src = opt->src;
                        no->external = opt->external;
                        no->quoted = opt->quoted;
+                       no->sepnodata = opt->sepnodata;
                }
        }
 
@@ -1184,6 +1191,11 @@ int mnt_opt_is_external(struct libmnt_opt *opt)
        return opt && opt->external ? 1 : 0;
 }
 
+int mnt_opt_is_sepnodata(struct libmnt_opt *opt)
+{
+       return opt->sepnodata;
+}
+
 
 #ifdef TEST_PROGRAM