]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Avoid buffer size warnings copying iface names
authorPhil Sutter <phil@nwl.cc>
Wed, 2 Jun 2021 09:58:06 +0000 (11:58 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 7 Jun 2021 12:50:27 +0000 (14:50 +0200)
The call to strncpy() is actually not needed: source buffer is only
IFNAMSIZ bytes large and guaranteed to be null-terminated. Use this to
avoid compiler warnings due to size parameter matching the destination
buffer size by performing the copy using (dumb) memcpy() instead.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft-ipv4.c
iptables/nft-ipv6.c

index a5b835b1f681db342debad17194097b94ecfcdac..34f94bd8cc24ab2e212579989e42d9760f40cc8b 100644 (file)
@@ -348,11 +348,11 @@ static void nft_ipv4_post_parse(int command,
         */
        cs->fw.ip.invflags = args->invflags;
 
-       strncpy(cs->fw.ip.iniface, args->iniface, IFNAMSIZ);
+       memcpy(cs->fw.ip.iniface, args->iniface, IFNAMSIZ);
        memcpy(cs->fw.ip.iniface_mask,
               args->iniface_mask, IFNAMSIZ*sizeof(unsigned char));
 
-       strncpy(cs->fw.ip.outiface, args->outiface, IFNAMSIZ);
+       memcpy(cs->fw.ip.outiface, args->outiface, IFNAMSIZ);
        memcpy(cs->fw.ip.outiface_mask,
               args->outiface_mask, IFNAMSIZ*sizeof(unsigned char));
 
index 46008fc5e762ab6f4afd478b35ef279322edc887..d9c9400ad7dc3e5a5e99de7cc58eb023f97d59c2 100644 (file)
@@ -293,11 +293,11 @@ static void nft_ipv6_post_parse(int command, struct iptables_command_state *cs,
         */
        cs->fw6.ipv6.invflags = args->invflags;
 
-       strncpy(cs->fw6.ipv6.iniface, args->iniface, IFNAMSIZ);
+       memcpy(cs->fw6.ipv6.iniface, args->iniface, IFNAMSIZ);
        memcpy(cs->fw6.ipv6.iniface_mask,
               args->iniface_mask, IFNAMSIZ*sizeof(unsigned char));
 
-       strncpy(cs->fw6.ipv6.outiface, args->outiface, IFNAMSIZ);
+       memcpy(cs->fw6.ipv6.outiface, args->outiface, IFNAMSIZ);
        memcpy(cs->fw6.ipv6.outiface_mask,
               args->outiface_mask, IFNAMSIZ*sizeof(unsigned char));