From: Phil Sutter <phil@nwl•cc>
To: Stephen Hemminger <stephen@networkplumber•org>
Cc: netdev@vger•kernel.org
Subject: Re: [iproute PATCH v2 4/7] lib/inet_proto: Make sure destination buffers are NULL-terminated
Date: Fri, 18 Aug 2017 18:55:20 +0200 [thread overview]
Message-ID: <20170818165520.GE16375@orbyte.nwl.cc> (raw)
In-Reply-To: <20170818093734.705f6742@xeon-e3>
On Fri, Aug 18, 2017 at 09:37:33AM -0700, Stephen Hemminger wrote:
> On Thu, 17 Aug 2017 19:09:29 +0200
> Phil Sutter <phil@nwl•cc> wrote:
>
> > Signed-off-by: Phil Sutter <phil@nwl•cc>
> > ---
> > lib/inet_proto.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/inet_proto.c b/lib/inet_proto.c
> > index ceda082b12a2e..87ed4769fc3da 100644
> > --- a/lib/inet_proto.c
> > +++ b/lib/inet_proto.c
> > @@ -35,8 +35,10 @@ const char *inet_proto_n2a(int proto, char *buf, int len)
> > pe = getprotobynumber(proto);
> > if (pe) {
> > icache = proto;
> > - strncpy(ncache, pe->p_name, 16);
> > - strncpy(buf, pe->p_name, len);
> > + strncpy(ncache, pe->p_name, 15);
> > + ncache[15] = '\0';
> > + strncpy(buf, pe->p_name, len - 1);
> > + buf[len] = '\0';
> > return buf;
> > }
> > snprintf(buf, len, "ipproto-%d", proto);
> > @@ -62,7 +64,8 @@ int inet_proto_a2n(const char *buf)
> > pe = getprotobyname(buf);
> > if (pe) {
> > icache = pe->p_proto;
> > - strncpy(ncache, pe->p_name, 16);
> > + strncpy(ncache, pe->p_name, 15);
> > + ncache[15] = '\0';
> > return pe->p_proto;
> > }
> > return -1;
>
> Depending on proto name to be 15 characters or less is a silly
> choice. Why not use strdup() and do it right?
Yes, I was puzzled by that as well. Luckily the longest proto name in my
/etc/protocols is rsvp-e2e-ignore which is 15 chars long. I'll change
the patch to use dynamic allocation.
Thanks, Phil
next prev parent reply other threads:[~2017-08-18 16:55 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
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 [this message]
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=20170818165520.GE16375@orbyte.nwl.cc \
--to=phil@nwl$(echo .)cc \
--cc=netdev@vger$(echo .)kernel.org \
--cc=stephen@networkplumber$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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