From: Phil Sutter Date: Thu, 5 Dec 2019 15:01:29 +0000 (+0100) Subject: xtables-translate: Guard strcpy() call in xlate_ifname() X-Git-Tag: v1.8.5~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2861bdbbf062071487a49103513d129ce40e2652;p=thirdparty%2Fiptables.git xtables-translate: Guard strcpy() call in xlate_ifname() 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") --- diff --git a/iptables/xtables-translate.c b/iptables/xtables-translate.c index a42c60a3..77a186b9 100644 --- a/iptables/xtables-translate.c +++ b/iptables/xtables-translate.c @@ -32,14 +32,13 @@ 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] = '*';