linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kconfig/lxdialog: replace strcpy with snprintf in print_autowrap
@ 2025-07-26 19:43 Suchit Karunakaran
  2025-07-29 14:11 ` Masahiro Yamada
  0 siblings, 1 reply; 2+ messages in thread
From: Suchit Karunakaran @ 2025-07-26 19:43 UTC (permalink / raw)
  To: masahiroy, nicolas.schier, linux-kbuild
  Cc: skhan, linux-kernel-mentees, linux-kernel, Suchit Karunakaran

strcpy() does not perform bounds checking and can lead to buffer overflows
if the source string exceeds the destination buffer size. In 
print_autowrap(), replace strcpy() with snprintf() to safely copy the 
prompt string into the fixed-size tempstr buffer.

Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
---
 scripts/kconfig/lxdialog/util.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index 964139c87fcb..b34000beb294 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -345,8 +345,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
 	int prompt_len, room, wlen;
 	char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0;
 
-	strcpy(tempstr, prompt);
-
+	snprintf(tempstr, sizeof(tempstr), "%s", prompt);
 	prompt_len = strlen(tempstr);
 
 	if (prompt_len <= width - x * 2) {	/* If prompt is short */
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kconfig/lxdialog: replace strcpy with snprintf in print_autowrap
  2025-07-26 19:43 [PATCH] kconfig/lxdialog: replace strcpy with snprintf in print_autowrap Suchit Karunakaran
@ 2025-07-29 14:11 ` Masahiro Yamada
  0 siblings, 0 replies; 2+ messages in thread
From: Masahiro Yamada @ 2025-07-29 14:11 UTC (permalink / raw)
  To: Suchit Karunakaran
  Cc: nicolas.schier, linux-kbuild, skhan, linux-kernel-mentees,
	linux-kernel

On Sun, Jul 27, 2025 at 4:43 AM Suchit Karunakaran
<suchitkarunakaran@gmail.com> wrote:
>
> strcpy() does not perform bounds checking and can lead to buffer overflows
> if the source string exceeds the destination buffer size. In
> print_autowrap(), replace strcpy() with snprintf() to safely copy the
> prompt string into the fixed-size tempstr buffer.
>
> Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
> ---

Applied to linux-kbuild.
Thanks.



>  scripts/kconfig/lxdialog/util.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
> index 964139c87fcb..b34000beb294 100644
> --- a/scripts/kconfig/lxdialog/util.c
> +++ b/scripts/kconfig/lxdialog/util.c
> @@ -345,8 +345,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
>         int prompt_len, room, wlen;
>         char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0;
>
> -       strcpy(tempstr, prompt);
> -
> +       snprintf(tempstr, sizeof(tempstr), "%s", prompt);
>         prompt_len = strlen(tempstr);
>
>         if (prompt_len <= width - x * 2) {      /* If prompt is short */
> --
> 2.50.1
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-29 14:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-26 19:43 [PATCH] kconfig/lxdialog: replace strcpy with snprintf in print_autowrap Suchit Karunakaran
2025-07-29 14:11 ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).