]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix options prepend/insert and merging
authorKarel Zak <kzak@redhat.com>
Mon, 22 May 2023 13:00:25 +0000 (15:00 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 22 May 2023 13:00:25 +0000 (15:00 +0200)
 * the order of the new options should not be changed
   (for example prepend "a,b,c" to list with "d" has to generate "a,b,c,d", not "c,b,a,d")

 * make sure that  options map is defined when merging options

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

index a8c1ad89a69931f2dff25d925cb06e67abafea25..f74e759287e7c2deab621f0fa97ce02ed951efe0 100644 (file)
@@ -338,6 +338,7 @@ int mnt_optlist_merge_opts(struct libmnt_optlist *ls)
 
                        /* remove inverted option */
                        else if (opt->ent && x->ent
+                           && opt->map == x->map
                            && opt->ent->id == x->ent->id
                            && (opt->ent->mask & MNT_INVERT
                                    || x->ent->mask & MNT_INVERT))
@@ -520,6 +521,8 @@ static int optlist_add_optstr(struct libmnt_optlist *ls, const char *optstr,
                if (!opt)
                        return -ENOMEM;
                opt->src = MNT_OPTSRC_STRING;
+               if (where)
+                       where = &opt->opts;
        }
 
        optlist_cleanup_cache(ls);
@@ -622,6 +625,8 @@ static int optlist_add_flags(struct libmnt_optlist *ls, unsigned long flags,
                if (!opt)
                        return -ENOMEM;
                opt->src = MNT_OPTSRC_FLAG;
+               if (where)
+                       where = &opt->opts;
        }
 
        optlist_cleanup_cache(ls);