From: Stephen Hemminger <stephen@networkplumber.org>
To: David Miller <davem@davemloft.net>
Cc: rickard_strandqvist@spectrumdigital.se, mlindner@marvell.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: ethernet: marvell: sky2.c: Cleaning up missing null-terminate in conjunction with strncpy
Date: Mon, 15 Sep 2014 13:53:39 -0700 [thread overview]
Message-ID: <20140915135339.0659f618@urahara> (raw)
In-Reply-To: <20140915.130721.589682835868904320.davem@davemloft.net>
On Mon, 15 Sep 2014 13:07:21 -0400 (EDT)
David Miller <davem@davemloft.net> wrote:
> From: Stephen Hemminger <stephen@networkplumber.org>
> Date: Sun, 14 Sep 2014 19:05:57 -0700
>
> > On Sun, 14 Sep 2014 19:33:43 +0200
> > Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> wrote:
> >
> >> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
> >>
> >> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> >> ---
> >> drivers/net/ethernet/marvell/sky2.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
> >> index dba48a5c..7053d38 100644
> >> --- a/drivers/net/ethernet/marvell/sky2.c
> >> +++ b/drivers/net/ethernet/marvell/sky2.c
> >> @@ -4907,7 +4907,7 @@ static const char *sky2_name(u8 chipid, char *buf, int sz)
> >> };
> >>
> >> if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2)
> >> - strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
> >> + strlcpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
> >> else
> >> snprintf(buf, sz, "(chip %#x)", chipid);
> >> return buf;
> >
> > Useless and unnecessary since the list of names is right there.
> > Why not avoid the copy all together?
> >
> > Subject: sky2: avoid strncpy
> >
> > Don't use strncpy() since security thought police think it is bad.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>
> I think providing the buffer on the stack of the thread executing the
> probe is superior because it will allow enabling parallel probing
> in the future.
>
> I don't think you have to change that aspect to achieve your goal
> of returning the const char * string when possible.
What is benefit of s/strncpy/strlcpy/ for known safe code?
Seems like more of the checkpatch police state.
next prev parent reply other threads:[~2014-09-15 20:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-14 17:33 [PATCH] net: ethernet: marvell: sky2.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-09-15 2:05 ` Stephen Hemminger
2014-09-15 17:07 ` David Miller
2014-09-15 20:53 ` Stephen Hemminger [this message]
2014-09-15 20:56 ` David Miller
2014-10-14 22:11 ` Rickard Strandqvist
2014-09-15 3:19 ` 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=20140915135339.0659f618@urahara \
--to=stephen@networkplumber.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mlindner@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=rickard_strandqvist@spectrumdigital.se \
/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).