]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: Fix for potential NULL-pointer deref
authorPhil Sutter <phil@nwl.cc>
Tue, 10 Jan 2023 21:36:58 +0000 (22:36 +0100)
committerPhil Sutter <phil@nwl.cc>
Fri, 13 Jan 2023 16:11:18 +0000 (17:11 +0100)
If memory allocation fails, calloc() returns NULL which was not checked
for. The code seems to expect zero array size though, so simply
replacing this call by one of the x*calloc() ones won't work. So guard
the call also by a check for 'len'.

Fixes: db0697ce7f602 ("src: support for flowtable listing")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/netlink.c

index 51de9c9c8edb2ee7ec7c2a33f314b678de299e26..efae125148b8c3b0f445825f5526c57818d9a765 100644 (file)
@@ -1790,7 +1790,8 @@ netlink_delinearize_flowtable(struct netlink_ctx *ctx,
        while (dev_array[len])
                len++;
 
-       flowtable->dev_array = calloc(1, len * sizeof(char *));
+       if (len)
+               flowtable->dev_array = xmalloc(len * sizeof(char *));
        for (i = 0; i < len; i++)
                flowtable->dev_array[i] = xstrdup(dev_array[i]);