Skip to contentSkip to conversation

kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c

PATCH Superseded Suchit Karunakaran 2 participants 3 messages Jul 26, 2025 – Jul 27, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c

strcpy() performs no bounds checking and can lead to buffer overflows if the input string exceeds the destination buffer size. This patch replaces it with strlcpy(), which ensures the input is always NULL-terminated, prevents overflows, following kernel coding guidelines.

Changes since v1:
- Replace strscpy with strlcpy

---
 scripts/kconfig/lxdialog/inputbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/lxdialog/inputbox.c +1 -1
index 3c6e24b20f5b..ca778e270346 100644
@@ -40,7 +40,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
 	if (!init)
 		instr[0] = '\0';
 	else
-		strcpy(instr, init);
+		strlcpy(instr, init, MAX_LEN + 1);
 
 do_resize:
 	if (getmaxy(stdscr) <= (height - INPUTBOX_HEIGHT_MIN))
Signature · 1 line
2.50.1
#1 lore raw
Quoted 19 lines · Suchit Karunakaran

strcpy() performs no bounds checking and can lead to buffer overflows if the input string exceeds the destination buffer size. This patch replaces it with strlcpy(), which ensures the input is always NULL-terminated, prevents overflows, following kernel coding guidelines.

Changes since v1:
- Replace strscpy with strlcpy

---
 scripts/kconfig/lxdialog/inputbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/lxdialog/inputbox.c +0 -0
index 3c6e24b20f5b..ca778e270346 100644

scripts/kconfig/lxdialog/inputbox.c int dialog_inputbox(const char *title, const char *prompt, int height, int width · line 43

Quoted 5 lines
scripts/kconfig/lxdialog/inputbox.c +1 -1
@@ -40,7 +40,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
 	if (!init)
 		instr[0] = '\0';
 	else
-		strcpy(instr, init);
+		strlcpy(instr, init, MAX_LEN + 1);

oh, I am sorry for the bad recommendation. On my Debian bookworm arm64 machine (w/o libbsd0), this does not compile as strlcpy() is not available (same as reported by kernel test robot [1]). As libbsd0 it not a documented dependency, strlcpy() should then probably not be used either (and Documentation/process/deprecated.rst also argues against it).

So, keeping close to Masahiros mail [2] a few weeks ago, what about this?

	else {
		strncpy(instr, init, sizeof(dialog_input_result)-1);
		instr[sizeof(dialog_input_result)-1) = '\0';
	}

Kind regards,
Nicolas

[1]: https://lore.kernel.org/linux-kbuild/[email protected]/
[2]: https://lore.kernel.org/linux-kbuild/CAK7LNASH7HyQZtPjerws7K8Smn1OXeDAXODdB9VaULXiYOitQg@mail.gmail.com/

author
#2 lore raw
Quoted 34 lines · Nicolas Schier
Quoted 19 lines · Suchit Karunakaran

strcpy() performs no bounds checking and can lead to buffer overflows if the input string exceeds the destination buffer size. This patch replaces it with strlcpy(), which ensures the input is always NULL-terminated, prevents overflows, following kernel coding guidelines.

Changes since v1:
- Replace strscpy with strlcpy

---
 scripts/kconfig/lxdialog/inputbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/lxdialog/inputbox.c +0 -0
index 3c6e24b20f5b..ca778e270346 100644

scripts/kconfig/lxdialog/inputbox.c int dialog_inputbox(const char *title, const char *prompt, int height, int width · line 43

Quoted 5 lines
scripts/kconfig/lxdialog/inputbox.c +1 -1
@@ -40,7 +40,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
      if (!init)
              instr[0] = '\0';
      else
-             strcpy(instr, init);
+             strlcpy(instr, init, MAX_LEN + 1);

oh, I am sorry for the bad recommendation. On my Debian bookworm arm64 machine (w/o libbsd0), this does not compile as strlcpy() is not available (same as reported by kernel test robot [1]). As libbsd0 it not a documented dependency, strlcpy() should then probably not be used either (and Documentation/process/deprecated.rst also argues against it).

Quoted 8 lines

So, keeping close to Masahiros mail [2] a few weeks ago, what about this?

        else {
                strncpy(instr, init, sizeof(dialog_input_result)-1);
                instr[sizeof(dialog_input_result)-1) = '\0';
        }

Yeah even I faced the same error. I initially tested it on Arch Linux and it worked somehow. However, it didn't work on Debian. I'll send v3 with the changes as you suggested. Thanks for reviewing.