]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-translate: Guard strcpy() call in xlate_ifname()
authorPhil Sutter <phil@nwl.cc>
Thu, 5 Dec 2019 15:01:29 +0000 (16:01 +0100)
committerPhil Sutter <phil@nwl.cc>
Fri, 6 Dec 2019 11:12:08 +0000 (12:12 +0100)
The function potentially fed overlong strings to strcpy(). Given that
everything needed to avoid this is there, reorder code a bit to prevent
those inputs, too.

Fixes: 0ddd663e9c167 ("iptables-translate: add in/out ifname wildcard match translation to nft")
iptables/xtables-translate.c

index a42c60a3b64c6309293a6f024f07860219b40536..77a186b905d73686f530891d4c406cad0608c8ea 100644 (file)
 void xlate_ifname(struct xt_xlate *xl, const char *nftmeta, const char *ifname,
                  bool invert)
 {
+       int ifaclen = strlen(ifname);
        char iface[IFNAMSIZ];
-       int ifaclen;
 
-       if (ifname[0] == '\0')
+       if (ifaclen < 1 || ifaclen >= IFNAMSIZ)
                return;
 
        strcpy(iface, ifname);
-       ifaclen = strlen(iface);
        if (iface[ifaclen - 1] == '+')
                iface[ifaclen - 1] = '*';