Skip to content

Commit

Permalink
kdb: Use format-specifiers rather than memset() for padding in kdb_re…
Browse files Browse the repository at this point in the history
…ad()

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: [email protected]
Reviewed-by: Douglas Anderson <[email protected]>
Tested-by: Justin Stitt <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Daniel Thompson <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
daniel-thompson authored and AK-Papon committed Jun 19, 2024
1 parent 5c17963 commit 5dd79a4
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions kernel/debug/kdb/kdb_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,9 @@ static char *kdb_read(char *buffer, size_t bufsize)
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;
Expand Down

0 comments on commit 5dd79a4

Please sign in to comment.