lkml.org 
[lkml]   [2019]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kdb: Fix bound check compiler warning
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?


Daniel.

> kdb_printf(kdb_prompt_str);
> kdb_nextline = 1; /* Prompt and input resets line number */
> return kdb_read(buffer, bufsize);
> --
> 1.9.1
>

\
 
 \ /
  Last update: 2019-05-08 10:16    [W:0.071 / U:0.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site