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

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