]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libiptc: silence two comiler warnings
authorFlorian Westphal <fw@strlen.de>
Mon, 16 Sep 2019 13:44:48 +0000 (15:44 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 16 Sep 2019 13:44:48 +0000 (15:44 +0200)
avoid hyptothetical truncation by leaving space for triling zero byte.
silcences:

In file included from libip4tc.c:113:
libiptc.c: In function ‘iptcc_alloc_chain_head’:
libiptc.c:163:2: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
  163 |  strncpy(c->name, name, TABLE_MAXNAMELEN);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libiptc.c: In function ‘iptc_rename_chain’:
libiptc.c:2388:2: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
 2388 |  strncpy(c->name, newname, sizeof(IPT_CHAINLABEL));
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Florian Westphal <fw@strlen.de>
libiptc/libiptc.c

index ee2b852157c5e27e271fb749ea3fc6784a2e3df4..58882015252132dd692b22b8859d421938efe3df 100644 (file)
@@ -160,7 +160,7 @@ static struct chain_head *iptcc_alloc_chain_head(const char *name, int hooknum)
                return NULL;
        memset(c, 0, sizeof(*c));
 
-       strncpy(c->name, name, TABLE_MAXNAMELEN);
+       strncpy(c->name, name, TABLE_MAXNAMELEN - 1);
        c->hooknum = hooknum;
        INIT_LIST_HEAD(&c->rules);
 
@@ -2385,7 +2385,7 @@ int TC_RENAME_CHAIN(const IPT_CHAINLABEL oldname,
        iptcc_chain_index_delete_chain(c, handle);
 
        /* Change the name of the chain */
-       strncpy(c->name, newname, sizeof(IPT_CHAINLABEL));
+       strncpy(c->name, newname, sizeof(IPT_CHAINLABEL) - 1);
 
        /* Insert sorted into to list again */
        iptc_insert_chain(handle, c);