Blame SOURCES/0004-flowtable-Correctly-check-realloc-call.patch

763a55
From 8f24f6eed8d905fb6b64d003ae3f4f1e657301aa Mon Sep 17 00:00:00 2001
763a55
From: Phil Sutter <psutter@redhat.com>
763a55
Date: Fri, 6 Dec 2019 17:31:16 +0100
763a55
Subject: [PATCH] flowtable: Correctly check realloc() call
763a55
763a55
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1778952
763a55
Upstream Status: libnftnl commit 835d645f40525
763a55
763a55
commit 835d645f4052551c5c1829c37a07c882f2260f65
763a55
Author: Phil Sutter <phil@nwl.cc>
763a55
Date:   Mon Dec 2 23:08:07 2019 +0100
763a55
763a55
    flowtable: Correctly check realloc() call
763a55
763a55
    If realloc() fails, it returns NULL but the original pointer is
763a55
    untouchted and therefore still has to be freed. Unconditionally
763a55
    overwriting the old pointer is therefore a bad idea, use a temporary
763a55
    variable instead.
763a55
763a55
    Fixes: 7f99639dd9217 ("flowtable: device array dynamic allocation")
763a55
    Signed-off-by: Phil Sutter <phil@nwl.cc>
763a55
    Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
763a55
---
763a55
 src/flowtable.c | 11 +++++------
763a55
 1 file changed, 5 insertions(+), 6 deletions(-)
763a55
763a55
diff --git a/src/flowtable.c b/src/flowtable.c
763a55
index db31943..9ba3b6d 100644
763a55
--- a/src/flowtable.c
763a55
+++ b/src/flowtable.c
763a55
@@ -388,7 +388,7 @@ static int nftnl_flowtable_parse_hook_cb(const struct nlattr *attr, void *data)
763a55
 static int nftnl_flowtable_parse_devs(struct nlattr *nest,
763a55
 				      struct nftnl_flowtable *c)
763a55
 {
763a55
-	const char **dev_array;
763a55
+	const char **dev_array, **tmp;
763a55
 	int len = 0, size = 8;
763a55
 	struct nlattr *attr;
763a55
 
763a55
@@ -401,14 +401,13 @@ static int nftnl_flowtable_parse_devs(struct nlattr *nest,
763a55
 			goto err;
763a55
 		dev_array[len++] = strdup(mnl_attr_get_str(attr));
763a55
 		if (len >= size) {
763a55
-			dev_array = realloc(dev_array,
763a55
-					    size * 2 * sizeof(char *));
763a55
-			if (!dev_array)
763a55
+			tmp = realloc(dev_array, size * 2 * sizeof(char *));
763a55
+			if (!tmp)
763a55
 				goto err;
763a55
 
763a55
 			size *= 2;
763a55
-			memset(&dev_array[len], 0,
763a55
-			       (size - len) * sizeof(char *));
763a55
+			memset(&tmp[len], 0, (size - len) * sizeof(char *));
763a55
+			dev_array = tmp;
763a55
 		}
763a55
 	}
763a55
 
763a55
-- 
763a55
1.8.3.1
763a55