72 lines
2.2 KiB
Diff
72 lines
2.2 KiB
Diff
|
From 6509f63cb68ea2dd737f9b52c146803402efcd7a Mon Sep 17 00:00:00 2001
|
||
|
From: Pablo Neira Ayuso <pablo@netfilter.org>
|
||
|
Date: Mon, 14 Jun 2021 14:47:47 +0200
|
||
|
Subject: [PATCH] src: add xzalloc_array() and use it to allocate the
|
||
|
expression hashtable
|
||
|
|
||
|
Otherwise, assertion to ensure that no colission occur is hit due to
|
||
|
uninitialized hashtable memory area:
|
||
|
|
||
|
nft: netlink_delinearize.c:1741: expr_handler_init: Assertion `expr_handle_ht[hash] == NULL' failed.
|
||
|
|
||
|
Fixes: c4058f96c6a5 ("netlink_delinearize: Fix suspicious calloc() call")
|
||
|
Acked-by: Phil Sutter <phil@nwl.cc>
|
||
|
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
||
|
(cherry picked from commit b0e7b294224030abc534c396fffcab9fbce12b11)
|
||
|
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||
|
---
|
||
|
include/utils.h | 1 +
|
||
|
src/netlink_delinearize.c | 2 +-
|
||
|
src/utils.c | 10 ++++++++++
|
||
|
3 files changed, 12 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/include/utils.h b/include/utils.h
|
||
|
index f45f25132d18d..ffbe2cbb75be5 100644
|
||
|
--- a/include/utils.h
|
||
|
+++ b/include/utils.h
|
||
|
@@ -133,6 +133,7 @@ extern void *xmalloc(size_t size);
|
||
|
extern void *xmalloc_array(size_t nmemb, size_t size);
|
||
|
extern void *xrealloc(void *ptr, size_t size);
|
||
|
extern void *xzalloc(size_t size);
|
||
|
+extern void *xzalloc_array(size_t nmemb, size_t size);
|
||
|
extern char *xstrdup(const char *s);
|
||
|
extern void xstrunescape(const char *in, char *out);
|
||
|
|
||
|
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
|
||
|
index 152b3e6cf8c65..7665d6f29c602 100644
|
||
|
--- a/src/netlink_delinearize.c
|
||
|
+++ b/src/netlink_delinearize.c
|
||
|
@@ -1732,7 +1732,7 @@ void expr_handler_init(void)
|
||
|
unsigned int i;
|
||
|
uint32_t hash;
|
||
|
|
||
|
- expr_handle_ht = xmalloc_array(NFT_EXPR_HSIZE,
|
||
|
+ expr_handle_ht = xzalloc_array(NFT_EXPR_HSIZE,
|
||
|
sizeof(expr_handle_ht[0]));
|
||
|
|
||
|
for (i = 0; i < array_size(netlink_parsers); i++) {
|
||
|
diff --git a/src/utils.c b/src/utils.c
|
||
|
index 47f5b791547b1..925841c571f5d 100644
|
||
|
--- a/src/utils.c
|
||
|
+++ b/src/utils.c
|
||
|
@@ -50,6 +50,16 @@ void *xmalloc_array(size_t nmemb, size_t size)
|
||
|
return xmalloc(nmemb * size);
|
||
|
}
|
||
|
|
||
|
+void *xzalloc_array(size_t nmemb, size_t size)
|
||
|
+{
|
||
|
+ void *ptr;
|
||
|
+
|
||
|
+ ptr = xmalloc_array(nmemb, size);
|
||
|
+ memset(ptr, 0, nmemb * size);
|
||
|
+
|
||
|
+ return ptr;
|
||
|
+}
|
||
|
+
|
||
|
void *xrealloc(void *ptr, size_t size)
|
||
|
{
|
||
|
ptr = realloc(ptr, size);
|
||
|
--
|
||
|
2.31.1
|
||
|
|