]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
kdb: Fix bound check compiler warning
authorWenlin Kang <wenlin.kang@windriver.com>
Mon, 13 May 2019 08:57:20 +0000 (16:57 +0800)
committerDaniel Thompson <daniel.thompson@linaro.org>
Tue, 14 May 2019 12:44:24 +0000 (13:44 +0100)
The strncpy() function may leave the destination string buffer
unterminated, better use strscpy() 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>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
kernel/debug/kdb/kdb_io.c

index 6a4b41484afe654572f3b4f37186046c4541c8e5..3a5184eb6977d430f9df84493340ceaafe2cefde 100644 (file)
@@ -446,7 +446,7 @@ poll_again:
 char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
 {
        if (prompt && kdb_prompt_str != prompt)
-               strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
+               strscpy(kdb_prompt_str, prompt, CMD_BUFLEN);
        kdb_printf(kdb_prompt_str);
        kdb_nextline = 1;       /* Prompt and input resets line number */
        return kdb_read(buffer, bufsize);