Re: [PATCH] kdb: use sizeof(kdb_prompt_str) instead of mismatched CMD_BUFLEN
From: David Laight
Date: Tue Jun 16 2026 - 16:20:38 EST
On Tue, 16 Jun 2026 22:14:54 +0530
Naveen Kumar Chaudhary <naveen.osdev@xxxxxxxxx> wrote:
> kdb_main.c defines CMD_BUFLEN as 200 (for command history buffers),
> while kdb_io.c defines it as 256 (for kdb_prompt_str). The snprintf()
> filling kdb_prompt_str incorrectly used the local CMD_BUFLEN (200),
> truncating the prompt unnecessarily. Use sizeof(kdb_prompt_str) to
> always match the actual buffer size.
As a matter of interest what sets the string that kdbgetenv("PROMPT")
returns?
If it is user settable, using it as a format string doesn't seem wise
(even for kdbg).
David
>
> Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@xxxxxxxxx>
> ---
> kernel/debug/kdb/kdb_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> index ddce56b47b25..571e9e61b40e 100644
> --- a/kernel/debug/kdb/kdb_main.c
> +++ b/kernel/debug/kdb/kdb_main.c
> @@ -1265,8 +1265,8 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
>
> do_full_getstr:
> /* PROMPT can only be set if we have MEM_READ permission. */
> - snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT"),
> - raw_smp_processor_id());
> + snprintf(kdb_prompt_str, sizeof(kdb_prompt_str),
> + kdbgetenv("PROMPT"), raw_smp_processor_id());
>
> /*
> * Fetch command from keyboard