Skip to content

Commit c9b51dd

Browse files
author
Daniel Thompson
committed
kdb: Use format-specifiers rather than memset() for padding in kdb_read()
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>
1 parent 6244917 commit c9b51dd

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

kernel/debug/kdb/kdb_io.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,9 @@ static char *kdb_read(char *buffer, size_t bufsize)
318318
break;
319319
case 14: /* Down */
320320
case 16: /* Up */
321-
memset(tmpbuffer, ' ',
322-
strlen(kdb_prompt_str) + (lastchar-buffer));
323-
*(tmpbuffer+strlen(kdb_prompt_str) +
324-
(lastchar-buffer)) = '\0';
325-
kdb_printf("\r%s\r", tmpbuffer);
321+
kdb_printf("\r%*c\r",
322+
(int)(strlen(kdb_prompt_str) + (lastchar - buffer)),
323+
' ');
326324
*lastchar = (char)key;
327325
*(lastchar+1) = '\0';
328326
return lastchar;

0 commit comments

Comments
 (0)