]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libiptc: Simplify alloc_handle() function signature
authorPhil Sutter <phil@nwl.cc>
Wed, 19 Sep 2018 13:16:53 +0000 (15:16 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 24 Sep 2018 09:24:06 +0000 (11:24 +0200)
This change originated from covscan complaining about the strcpy() call
with an unknown size source buffer. But in fact, the size is known (and
equal to the destination size), so pass a pointer to STRUCT_GETINFO to
alloc_handle() instead of it's fields separately. Hopefully this will
silence covscan.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
libiptc/libiptc.c

index 6eacdddd09a1c72b715c2e604378e03975249677..7c3cb9e7cf0768daf9a56b3b0b61be20ea18a86a 100644 (file)
@@ -1270,7 +1270,7 @@ static int iptcc_compile_table(struct xtc_handle *h, STRUCT_REPLACE *repl)
 
 /* Allocate handle of given size */
 static struct xtc_handle *
-alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
+alloc_handle(STRUCT_GETINFO *infop)
 {
        struct xtc_handle *h;
 
@@ -1281,14 +1281,14 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
        }
        memset(h, 0, sizeof(*h));
        INIT_LIST_HEAD(&h->chains);
-       strcpy(h->info.name, tablename);
+       strcpy(h->info.name, infop->name);
 
-       h->entries = malloc(sizeof(STRUCT_GET_ENTRIES) + size);
+       h->entries = malloc(sizeof(STRUCT_GET_ENTRIES) + infop->size);
        if (!h->entries)
                goto out_free_handle;
 
-       strcpy(h->entries->name, tablename);
-       h->entries->size = size;
+       strcpy(h->entries->name, infop->name);
+       h->entries->size = infop->size;
 
        return h;
 
@@ -1337,8 +1337,8 @@ retry:
        DEBUGP("valid_hooks=0x%08x, num_entries=%u, size=%u\n",
                info.valid_hooks, info.num_entries, info.size);
 
-       if ((h = alloc_handle(info.name, info.size, info.num_entries))
-           == NULL) {
+       h = alloc_handle(&info);
+       if (h == NULL) {
                close(sockfd);
                return NULL;
        }