Blame SOURCES/0105-ipntable-Avoid-memory-allocation-for-filter.name.patch

99be8f
From c176919cbf8f11f666c2281785e58fd147ecfea0 Mon Sep 17 00:00:00 2001
99be8f
From: Andrea Claudi <aclaudi@redhat.com>
99be8f
Date: Mon, 29 Apr 2019 20:08:08 +0200
99be8f
Subject: [PATCH] ipntable: Avoid memory allocation for filter.name
99be8f
99be8f
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
99be8f
Upstream Status: iproute2.git commit 45c2ec9e95fef
99be8f
99be8f
commit 45c2ec9e95fef8eb6f0807d9a7e5f14c14313c7e
99be8f
Author: Phil Sutter <phil@nwl.cc>
99be8f
Date:   Thu Aug 24 11:51:45 2017 +0200
99be8f
99be8f
    ipntable: Avoid memory allocation for filter.name
99be8f
99be8f
    The original issue was that filter.name might end up unterminated if
99be8f
    user provided string was too long. But in fact it is not necessary to
99be8f
    copy the commandline parameter at all: just make filter.name point to it
99be8f
    instead.
99be8f
99be8f
    Signed-off-by: Phil Sutter <phil@nwl.cc>
99be8f
---
99be8f
 ip/ipntable.c | 6 +++---
99be8f
 1 file changed, 3 insertions(+), 3 deletions(-)
99be8f
99be8f
diff --git a/ip/ipntable.c b/ip/ipntable.c
99be8f
index ae8c74ead2cb8..2f72c989f35df 100644
99be8f
--- a/ip/ipntable.c
99be8f
+++ b/ip/ipntable.c
99be8f
@@ -37,7 +37,7 @@ static struct
99be8f
 	int family;
99be8f
 	int index;
99be8f
 #define NONE_DEV	(-1)
99be8f
-	char name[1024];
99be8f
+	const char *name;
99be8f
 } filter;
99be8f
 
99be8f
 static void usage(void) __attribute__((noreturn));
99be8f
@@ -367,7 +367,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
99be8f
 	if (tb[NDTA_NAME]) {
99be8f
 		const char *name = rta_getattr_str(tb[NDTA_NAME]);
99be8f
 
99be8f
-		if (strlen(filter.name) > 0 && strcmp(filter.name, name))
99be8f
+		if (filter.name && strcmp(filter.name, name))
99be8f
 			return 0;
99be8f
 	}
99be8f
 	if (tb[NDTA_PARMS]) {
99be8f
@@ -631,7 +631,7 @@ static int ipntable_show(int argc, char **argv)
99be8f
 		} else if (strcmp(*argv, "name") == 0) {
99be8f
 			NEXT_ARG();
99be8f
 
99be8f
-			strncpy(filter.name, *argv, sizeof(filter.name));
99be8f
+			filter.name = *argv;
99be8f
 		} else
99be8f
 			invarg("unknown", *argv);
99be8f
 
99be8f
-- 
99be8f
2.20.1
99be8f