netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH v4 1/6] ipntable: Avoid memory allocation for filter.name
Date: Thu, 24 Aug 2017 11:51:45 +0200	[thread overview]
Message-ID: <20170824095150.5469-2-phil@nwl.cc> (raw)
In-Reply-To: <20170824095150.5469-1-phil@nwl.cc>

The original issue was that filter.name might end up unterminated if
user provided string was too long. But in fact it is not necessary to
copy the commandline parameter at all: just make filter.name point to it
instead.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 ip/ipntable.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ip/ipntable.c b/ip/ipntable.c
index 1837909fa42e7..88236ce0ec1e1 100644
--- a/ip/ipntable.c
+++ b/ip/ipntable.c
@@ -37,7 +37,7 @@ static struct
 	int family;
 	int index;
 #define NONE_DEV	(-1)
-	char name[1024];
+	const char *name;
 } filter;
 
 static void usage(void) __attribute__((noreturn));
@@ -367,7 +367,7 @@ static int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void
 	if (tb[NDTA_NAME]) {
 		const char *name = rta_getattr_str(tb[NDTA_NAME]);
 
-		if (strlen(filter.name) > 0 && strcmp(filter.name, name))
+		if (filter.name && strcmp(filter.name, name))
 			return 0;
 	}
 	if (tb[NDTA_PARMS]) {
@@ -631,7 +631,7 @@ static int ipntable_show(int argc, char **argv)
 		} else if (strcmp(*argv, "name") == 0) {
 			NEXT_ARG();
 
-			strncpy(filter.name, *argv, sizeof(filter.name));
+			filter.name = *argv;
 		} else
 			invarg("unknown", *argv);
 
-- 
2.13.1

  reply	other threads:[~2017-08-24  9:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24  9:51 [iproute PATCH v4 0/6] Covscan: Fixes for string termination Phil Sutter
2017-08-24  9:51 ` Phil Sutter [this message]
2017-08-24  9:51 ` [iproute PATCH v4 2/6] lib/fs: Fix format string in find_fs_mount() Phil Sutter
2017-08-24  9:51 ` [iproute PATCH v4 3/6] lib/inet_proto: Review inet_proto_{a2n,n2a}() Phil Sutter
2017-08-24  9:51 ` [iproute PATCH v4 4/6] lnstat_util: Simplify alloc_and_open() a bit Phil Sutter
2017-08-24  9:51 ` [iproute PATCH v4 5/6] tc/m_xt: Fix for potential string buffer overflows Phil Sutter
2017-08-24  9:51 ` [iproute PATCH v4 6/6] lib/ll_map: Choose size of new cache items at run-time Phil Sutter
2017-08-24 22:16 ` [iproute PATCH v4 0/6] Covscan: Fixes for string termination Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170824095150.5469-2-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).