All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [iproute PATCH v2 1/7] ipntable: Make sure filter.name is NULL-terminated
Date: Fri, 18 Aug 2017 12:52:24 +0200	[thread overview]
Message-ID: <20170818105224.GG10864@orbyte.nwl.cc> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DD005A7B4@AcuExch.aculab.com>

Hi David,

On Fri, Aug 18, 2017 at 09:19:16AM +0000, David Laight wrote:
> From: Phil Sutter
> > Sent: 17 August 2017 18:09
> > To: Stephen Hemminger
> > Cc: netdev@vger.kernel.org
> > Subject: [iproute PATCH v2 1/7] ipntable: Make sure filter.name is NULL-terminated
> > 
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> >  ip/ipntable.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/ip/ipntable.c b/ip/ipntable.c
> > index 879626ee4f491..7be1f04d33d90 100644
> > --- a/ip/ipntable.c
> > +++ b/ip/ipntable.c
> > @@ -633,7 +633,8 @@ static int ipntable_show(int argc, char **argv)
> >  		} else if (strcmp(*argv, "name") == 0) {
> >  			NEXT_ARG();
> > 
> > -			strncpy(filter.name, *argv, sizeof(filter.name));
> > +			strncpy(filter.name, *argv, sizeof(filter.name) - 1);
> > +			filter.name[sizeof(filter.name) - 1] = '\0';
> 
> Why not check for overflow instead?
> 			if (filter.name[sizeof(filter.name) - 1])
> 				usage("filer name too long");

sizeof(filter.name) is 1024, which is maybe a bit over the top for
something a user would input. So I found a better way avoiding all this
at once: I made filter.name a const char *, then just assigned *argv to
it. This should be safe since rtnl_dump_filter() and therefore
print_ntable() callback is called from inside ipntable_show() so *argv
is not accessed outside of it's scope.

What do you think?

Thanks, Phil

  reply	other threads:[~2017-08-18 10:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17 17:09 [iproute PATCH v2 0/7] Covscan: Fixes for string termination Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 1/7] ipntable: Make sure filter.name is NULL-terminated Phil Sutter
2017-08-18  9:19   ` David Laight
2017-08-18 10:52     ` Phil Sutter [this message]
2017-08-18 16:32       ` David Laight
2017-08-18 16:52         ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 2/7] xfrm_state: Make sure alg_name " Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 3/7] lib/fs: Fix format string in find_fs_mount() Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 4/7] lib/inet_proto: Make sure destination buffers are NULL-terminated Phil Sutter
2017-08-18 16:37   ` Stephen Hemminger
2017-08-18 16:55     ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 5/7] lnstat_util: Simplify alloc_and_open() a bit Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 6/7] tc/m_xt: Fix for potential string buffer overflows Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 7/7] lib/ll_map: Make sure im->name is NULL-terminated Phil Sutter
2017-08-18 16:33   ` 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=20170818105224.GG10864@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=David.Laight@ACULAB.COM \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.