From: Daniel Thompson <daniel.thompson@linaro.org>
To: Wenlin Kang <wenlin.kang@windriver.com>
Cc: jason.wessel@windriver.com, prarit@redhat.com,
kgdb-bugreport@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kdb: Fix bound check compiler warning
Date: Mon, 13 May 2019 08:44:44 +0100 [thread overview]
Message-ID: <20190513074444.eftse5jimrl4xtc7@holly.lan> (raw)
In-Reply-To: <0c5121f7-645c-3651-cccc-2ae836d415b6@windriver.com>
On Mon, May 13, 2019 at 11:39:47AM +0800, Wenlin Kang wrote:
> On 5/12/19 5:00 PM, Daniel Thompson wrote:
> > On Thu, May 09, 2019 at 10:56:03AM +0800, Wenlin Kang wrote:
> > > On 5/8/19 4:16 PM, Daniel Thompson wrote:
> > > > On Wed, May 08, 2019 at 09:52:39AM +0800, Wenlin Kang wrote:
> > > > > The strncpy() function may leave the destination string buffer
> > > > > unterminated, better use strlcpy() instead.
> > > > >
> > > > > This fixes the following warning with gcc 8.2:
> > > > >
> > > > > kernel/debug/kdb/kdb_io.c: In function 'kdb_getstr':
> > > > > kernel/debug/kdb/kdb_io.c:449:3: warning: 'strncpy' specified bound 256 equals destination size [-Wstringop-truncation]
> > > > > strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
> > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > > >
> > > > > Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
> > > > > ---
> > > > > kernel/debug/kdb/kdb_io.c | 2 +-
> > > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> > > > > index 6a4b414..7fd4513 100644
> > > > > --- a/kernel/debug/kdb/kdb_io.c
> > > > > +++ b/kernel/debug/kdb/kdb_io.c
> > > > > @@ -446,7 +446,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
> > > > > char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
> > > > > {
> > > > > if (prompt && kdb_prompt_str != prompt)
> > > > > - strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
> > > > > + strlcpy(kdb_prompt_str, prompt, CMD_BUFLEN);
> > > > Shouldn't that be strscpy?
> > >
> > > Hi Daniel
> > >
> > > I thought about strscpy, but I think strlcpy is better, because it only copy
> > > the real number of characters if src string less than that size.
> > Sorry, I'm confused by this. What behavior does strscpy() have that you
> > consider undesirable in this case?
>
>
> Hi Daniel
>
> I checked strscpy() again, and think either is fine to me, if you think
> strscpy() is better, I can change it to this, and send v2, thanks for your
> review.
I think strscpy() is better.
Daniel.
>
>
> >
> > Daniel.
> >
>
> --
> Thanks,
> Wenlin Kang
>
prev parent reply other threads:[~2019-05-13 7:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-08 1:52 Wenlin Kang
2019-05-08 8:16 ` Daniel Thompson
2019-05-09 2:56 ` Wenlin Kang
2019-05-12 9:00 ` Daniel Thompson
2019-05-13 3:39 ` Wenlin Kang
2019-05-13 7:44 ` Daniel Thompson [this message]
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=20190513074444.eftse5jimrl4xtc7@holly.lan \
--to=daniel.thompson@linaro.org \
--cc=jason.wessel@windriver.com \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=prarit@redhat.com \
--cc=wenlin.kang@windriver.com \
/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
all inboxes | Powered by JetHome®