Blame SOURCES/0005-chain-Correctly-check-realloc-call.patch

6ed431
From 2facd747b6bbcd3716841e6213b7b9e9b94c556a Mon Sep 17 00:00:00 2001
6ed431
From: Phil Sutter <psutter@redhat.com>
6ed431
Date: Fri, 6 Dec 2019 17:31:16 +0100
6ed431
Subject: [PATCH] chain: Correctly check realloc() call
6ed431
6ed431
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1778952
6ed431
Upstream Status: libnftnl commit d95a703746d53
6ed431
6ed431
commit d95a703746d5394d56a9f464e343594e4882da0d
6ed431
Author: Phil Sutter <phil@nwl.cc>
6ed431
Date:   Mon Dec 2 23:12:34 2019 +0100
6ed431
6ed431
    chain: Correctly check realloc() call
6ed431
6ed431
    If realloc() fails, it returns NULL but the original pointer is
6ed431
    untouchted and therefore still has to be freed. Unconditionally
6ed431
    overwriting the old pointer is therefore a bad idea, use a temporary
6ed431
    variable instead.
6ed431
6ed431
    Fixes: e3ac19b5ec162 ("chain: multi-device support")
6ed431
    Signed-off-by: Phil Sutter <phil@nwl.cc>
6ed431
    Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6ed431
---
6ed431
 src/chain.c | 11 +++++------
6ed431
 1 file changed, 5 insertions(+), 6 deletions(-)
6ed431
6ed431
diff --git a/src/chain.c b/src/chain.c
6ed431
index 9cc8735..b9a16fc 100644
6ed431
--- a/src/chain.c
6ed431
+++ b/src/chain.c
6ed431
@@ -605,7 +605,7 @@ static int nftnl_chain_parse_hook_cb(const struct nlattr *attr, void *data)
6ed431
 
6ed431
 static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c)
6ed431
 {
6ed431
-	const char **dev_array;
6ed431
+	const char **dev_array, **tmp;
6ed431
 	int len = 0, size = 8;
6ed431
 	struct nlattr *attr;
6ed431
 
6ed431
@@ -618,14 +618,13 @@ static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c)
6ed431
 			goto err;
6ed431
 		dev_array[len++] = strdup(mnl_attr_get_str(attr));
6ed431
 		if (len >= size) {
6ed431
-			dev_array = realloc(dev_array,
6ed431
-					    size * 2 * sizeof(char *));
6ed431
-			if (!dev_array)
6ed431
+			tmp = realloc(dev_array, size * 2 * sizeof(char *));
6ed431
+			if (!tmp)
6ed431
 				goto err;
6ed431
 
6ed431
 			size *= 2;
6ed431
-			memset(&dev_array[len], 0,
6ed431
-			       (size - len) * sizeof(char *));
6ed431
+			memset(&tmp[len], 0, (size - len) * sizeof(char *));
6ed431
+			dev_array = tmp;
6ed431
 		}
6ed431
 	}
6ed431
 
6ed431
-- 
6ed431
1.8.3.1
6ed431