Skip to contentSkip to conversation

kconfig/lxdialog: replace strcpy with snprintf in print_autowrap

PATCH In review Suchit Karunakaran 2 participants 2 messages Jul 26, 2025 – Jul 29, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig/lxdialog: replace strcpy with snprintf in print_autowrap

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.

---
 scripts/kconfig/lxdialog/util.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/kconfig/lxdialog/util.c +1 -2
index 964139c87fcb..b34000beb294 100644
@@ -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 */
Signature · 1 line
2.50.1
#1 lore raw
Quoted 8 lines · 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.

---

Applied to linux-kbuild.
Thanks.

Quoted 20 lines
 scripts/kconfig/lxdialog/util.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/kconfig/lxdialog/util.c +1 -3
index 964139c87fcb..b34000beb294 100644
@@ -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

Signature · 2 lines
Best Regards
Masahiro Yamada