]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
mnl: Drop asterisk from end of NFTA_DEVICE_PREFIX strings
authorPhil Sutter <phil@nwl.cc>
Tue, 7 Oct 2025 15:51:32 +0000 (17:51 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 8 Oct 2025 12:14:05 +0000 (14:14 +0200)
The asterisk left in place becomes part of the prefix by accident and is thus
both included when matching interface names as well as dumped back to user
space.

Fixes: c31e887504a90 ("mnl: Support simple wildcards in netdev hooks")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/mnl.c

index bba34b73a708f15373fda557844f098f399298f4..ab4a7dbc8d252819e261b3744ba354518ab545e2 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -815,9 +815,16 @@ static bool is_wildcard_str(const char *str)
 
 static void mnl_nft_attr_put_ifname(struct nlmsghdr *nlh, const char *ifname)
 {
-       uint16_t attr = is_wildcard_str(ifname) ?
-                       NFTA_DEVICE_PREFIX : NFTA_DEVICE_NAME;
+       uint16_t attr = NFTA_DEVICE_NAME;
+       char pfx[IFNAMSIZ];
 
+       if (is_wildcard_str(ifname)) {
+               snprintf(pfx, IFNAMSIZ, "%s", ifname);
+               pfx[strlen(pfx) - 1] = '\0';
+
+               attr = NFTA_DEVICE_PREFIX;
+               ifname = pfx;
+       }
        mnl_attr_put_strz(nlh, attr, ifname);
 }