* [PATCH v2] kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c @ 2025-07-26 17:55 Suchit Karunakaran 2025-07-27 16:19 ` Nicolas Schier 0 siblings, 1 reply; 3+ messages in thread From: Suchit Karunakaran @ 2025-07-26 17:55 UTC (permalink / raw) To: masahiroy, nicolas.schier, linux-kbuild Cc: skhan, linux-kernel-mentees, linux-kernel, 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. Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> Changes since v1: - Replace strscpy with strlcpy --- scripts/kconfig/lxdialog/inputbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c index 3c6e24b20f5b..ca778e270346 100644 --- a/scripts/kconfig/lxdialog/inputbox.c +++ b/scripts/kconfig/lxdialog/inputbox.c @@ -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)) -- 2.50.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c 2025-07-26 17:55 [PATCH v2] kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c Suchit Karunakaran @ 2025-07-27 16:19 ` Nicolas Schier 2025-07-27 16:24 ` Suchit K 0 siblings, 1 reply; 3+ messages in thread From: Nicolas Schier @ 2025-07-27 16:19 UTC (permalink / raw) To: Suchit Karunakaran Cc: masahiroy, linux-kbuild, skhan, linux-kernel-mentees, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1823 bytes --] On Sat, Jul 26, 2025 at 11:25:24PM +0530, Suchit Karunakaran wrote: > 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. > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > Changes since v1: > - Replace strscpy with strlcpy > > --- > scripts/kconfig/lxdialog/inputbox.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c > index 3c6e24b20f5b..ca778e270346 100644 > --- a/scripts/kconfig/lxdialog/inputbox.c > +++ b/scripts/kconfig/lxdialog/inputbox.c > @@ -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/202507270411.j9vfofzH-lkp@intel.com/ [2]: https://lore.kernel.org/linux-kbuild/CAK7LNASH7HyQZtPjerws7K8Smn1OXeDAXODdB9VaULXiYOitQg@mail.gmail.com/ [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c 2025-07-27 16:19 ` Nicolas Schier @ 2025-07-27 16:24 ` Suchit K 0 siblings, 0 replies; 3+ messages in thread From: Suchit K @ 2025-07-27 16:24 UTC (permalink / raw) To: Nicolas Schier Cc: masahiroy, linux-kbuild, skhan, linux-kernel-mentees, linux-kernel On Sun, 27 Jul 2025 at 21:49, Nicolas Schier <nicolas.schier@linux.dev> wrote: > > On Sat, Jul 26, 2025 at 11:25:24PM +0530, Suchit Karunakaran wrote: > > 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. > > > > Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com> > > > > Changes since v1: > > - Replace strscpy with strlcpy > > > > --- > > scripts/kconfig/lxdialog/inputbox.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c > > index 3c6e24b20f5b..ca778e270346 100644 > > --- a/scripts/kconfig/lxdialog/inputbox.c > > +++ b/scripts/kconfig/lxdialog/inputbox.c > > @@ -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'; > } > 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. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-27 16:24 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-07-26 17:55 [PATCH v2] kconfig/lxdialog: replace strcpy() with strlcpy() in inputbox.c Suchit Karunakaran 2025-07-27 16:19 ` Nicolas Schier 2025-07-27 16:24 ` Suchit K
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox