From 5fd43ad39108b4e9d9de93b75c2c23d0eb645e9c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 18 Aug 2022 11:59:08 +0200 Subject: [PATCH] libmount: (optlist) de-duplicate also according to invert mask The last option is the winner, it means "noexec,exec" is "exec". Signed-off-by: Karel Zak --- libmount/src/optlist.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c index 8b2fe72293..7d66d1aa31 100644 --- a/libmount/src/optlist.c +++ b/libmount/src/optlist.c @@ -293,15 +293,29 @@ int mnt_optlist_merge_opts(struct libmnt_optlist *ls) mnt_reset_iter(&xtr, MNT_ITER_FORWARD); while (mnt_optlist_next_opt(ls, &xtr, &x) == 0) { + int rem = 0; + if (opt == x) break; /* no another instance */ - if (is_equal_opts(opt, x)) { + /* remove duplicate option */ + if (is_equal_opts(opt, x)) + rem = 1; + + /* remove inverted option */ + else if (opt->ent && x->ent + && opt->ent->id == x->ent->id + && (opt->ent->mask & MNT_INVERT + || x->ent->mask & MNT_INVERT)) + rem = 1; + + if (rem) { /* me sure @itr does not point to removed item */ if (itr.p == &x->opts) itr.p = x->opts.prev; mnt_optlist_remove_opt(ls, x); } + } } @@ -590,6 +604,8 @@ int mnt_optlist_get_flags(struct libmnt_optlist *ls, unsigned long *flags, mnt_reset_iter(&itr, MNT_ITER_FORWARD); while (mnt_optlist_next_opt(ls, &itr, &opt) == 0) { + if (map != opt->map) + continue; if (!opt->ent || !opt->ent->id) continue; if (opt->external && !(what & MNT_OL_FLTR_ALL)) -- 2.47.3