]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
nft: don't use xzalloc()
authorArturo Borrero Gonzalez <arturo@netfilter.org>
Mon, 1 Jul 2019 10:52:48 +0000 (12:52 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 1 Jul 2019 18:43:46 +0000 (20:43 +0200)
In the current setup, nft (the frontend object) is using the xzalloc() function
from libnftables, which does not makes sense, as this is typically an internal
helper function.

In order to don't use this public libnftables symbol (a later patch just
removes it), let's use calloc() directly in the nft frontend.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/main.c

index cbfd69a42d045fc1b4f1947023f7624d895f5c74..8e6c897cdd36c9fca5e566f542bfa5a09e0f02e6 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 
 #include <nftables/libnftables.h>
+#include <nftables.h>
 #include <utils.h>
 #include <cli.h>
 
@@ -302,7 +303,12 @@ int main(int argc, char * const *argv)
                for (len = 0, i = optind; i < argc; i++)
                        len += strlen(argv[i]) + strlen(" ");
 
-               buf = xzalloc(len);
+               buf = calloc(1, len);
+               if (buf == NULL) {
+                       fprintf(stderr, "%s:%u: Memory allocation failure\n",
+                               __FILE__, __LINE__);
+                       exit(NFT_EXIT_NOMEM);
+               }
                for (i = optind; i < argc; i++) {
                        strcat(buf, argv[i]);
                        if (i + 1 < argc)