From: Wenlin Kang <wenlin.kang@windriver.com>
To: Daniel Thompson <daniel.thompson@linaro.org>
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: Thu, 9 May 2019 10:56:03 +0800 [thread overview]
Message-ID: <ac8af42c-e69d-6fd0-1d76-73a37e8a672c@windriver.com> (raw)
In-Reply-To: <20190508081640.tvtnazr4tf5jijh7@holly.lan>
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.
>
>
> Daniel.
>
>> kdb_printf(kdb_prompt_str);
>> kdb_nextline = 1; /* Prompt and input resets line number */
>> return kdb_read(buffer, bufsize);
>> --
>> 1.9.1
>>
--
Thanks,
Wenlin Kang
next prev parent reply other threads:[~2019-05-09 2:56 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 [this message]
2019-05-12 9:00 ` Daniel Thompson
2019-05-13 3:39 ` Wenlin Kang
2019-05-13 7:44 ` Daniel Thompson
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=ac8af42c-e69d-6fd0-1d76-73a37e8a672c@windriver.com \
--to=wenlin.kang@windriver.com \
--cc=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 \
/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®