]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kdb: Use format-specifiers rather than memset() for padding in kdb_read()
authorDaniel Thompson <daniel.thompson@linaro.org>
Wed, 24 Apr 2024 14:03:38 +0000 (15:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:32:35 +0000 (13:32 +0200)
commit c9b51ddb66b1d96e4d364c088da0f1dfb004c574 upstream.

Currently when the current line should be removed from the display
kdb_read() uses memset() to fill a temporary buffer with spaces.
The problem is not that this could be trivially implemented using a
format string rather than open coding it. The real problem is that
it is possible, on systems with a long kdb_prompt_str, to write past
the end of the tmpbuffer.

Happily, as mentioned above, this can be trivially implemented using a
format string. Make it so!

Cc: stable@vger.kernel.org
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240424-kgdb_read_refactor-v3-5-f236dbe9828d@linaro.org
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/debug/kdb/kdb_io.c

index 91872c42cd7efd6338c65327d73bd6d8adf99efb..a3b4b55d2e2e1b901bd4e39c48d8563bcec24de1 100644 (file)
@@ -305,11 +305,9 @@ poll_again:
                break;
        case 14: /* Down */
        case 16: /* Up */
-               memset(tmpbuffer, ' ',
-                      strlen(kdb_prompt_str) + (lastchar-buffer));
-               *(tmpbuffer+strlen(kdb_prompt_str) +
-                 (lastchar-buffer)) = '\0';
-               kdb_printf("\r%s\r", tmpbuffer);
+               kdb_printf("\r%*c\r",
+                          (int)(strlen(kdb_prompt_str) + (lastchar - buffer)),
+                          ' ');
                *lastchar = (char)key;
                *(lastchar+1) = '\0';
                return lastchar;