* [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window()
@ 2025-08-10 14:22 Thorsten Blum
2025-08-11 0:19 ` Randy Dunlap
2025-08-11 12:51 ` Franco Martelli
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2025-08-10 14:22 UTC (permalink / raw)
To: Masahiro Yamada, Thorsten Blum, Randy Dunlap, Nicolas Schier,
Shankari Anand, nir.tzachar@gmail.com, Michal Marek
Cc: stable, linux-kbuild, linux-kernel
Use 'min(len, x)' as the index instead of just 'len' to NUL-terminate
the copied 'line' string at the correct position.
Add a newline after the local variable declarations to silence a
checkpatch warning.
Cc: stable@vger.kernel.org
Fixes: 692d97c380c6 ("kconfig: new configuration interface (nconfig)")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
scripts/kconfig/nconf.gui.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 7206437e784a..ec021ebd2c52 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -175,8 +175,9 @@ void fill_window(WINDOW *win, const char *text)
for (i = 0; i < total_lines; i++) {
char tmp[x+10];
const char *line = get_line(text, i);
- int len = get_line_length(line);
- strncpy(tmp, line, min(len, x));
+ int len = min(get_line_length(line), x);
+
+ strncpy(tmp, line, len);
tmp[len] = '\0';
mvwprintw(win, i, 0, "%s", tmp);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window()
2025-08-10 14:22 [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window() Thorsten Blum
@ 2025-08-11 0:19 ` Randy Dunlap
2025-08-11 12:51 ` Franco Martelli
1 sibling, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2025-08-11 0:19 UTC (permalink / raw)
To: Thorsten Blum, Masahiro Yamada, Nicolas Schier, Shankari Anand,
nir.tzachar@gmail.com, Michal Marek
Cc: stable, linux-kbuild, linux-kernel
On 8/10/25 7:22 AM, Thorsten Blum wrote:
> Use 'min(len, x)' as the index instead of just 'len' to NUL-terminate
> the copied 'line' string at the correct position.
>
> Add a newline after the local variable declarations to silence a
> checkpatch warning.
>
> Cc: stable@vger.kernel.org
> Fixes: 692d97c380c6 ("kconfig: new configuration interface (nconfig)")
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
LGTM. Thanks.
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
> ---
> scripts/kconfig/nconf.gui.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
> index 7206437e784a..ec021ebd2c52 100644
> --- a/scripts/kconfig/nconf.gui.c
> +++ b/scripts/kconfig/nconf.gui.c
> @@ -175,8 +175,9 @@ void fill_window(WINDOW *win, const char *text)
> for (i = 0; i < total_lines; i++) {
> char tmp[x+10];
> const char *line = get_line(text, i);
> - int len = get_line_length(line);
> - strncpy(tmp, line, min(len, x));
> + int len = min(get_line_length(line), x);
> +
> + strncpy(tmp, line, len);
> tmp[len] = '\0';
> mvwprintw(win, i, 0, "%s", tmp);
> }
--
~Randy
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window()
2025-08-10 14:22 [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window() Thorsten Blum
2025-08-11 0:19 ` Randy Dunlap
@ 2025-08-11 12:51 ` Franco Martelli
2025-08-11 15:08 ` Thorsten Blum
1 sibling, 1 reply; 5+ messages in thread
From: Franco Martelli @ 2025-08-11 12:51 UTC (permalink / raw)
To: Thorsten Blum, Masahiro Yamada, Randy Dunlap, Nicolas Schier,
Shankari Anand, nir.tzachar@gmail.com, Michal Marek
Cc: stable, linux-kbuild, linux-kernel
On 10/08/25 at 16:22, Thorsten Blum wrote:
> Use 'min(len, x)' as the index instead of just 'len' to NUL-terminate
> the copied 'line' string at the correct position.
>
> Add a newline after the local variable declarations to silence a
> checkpatch warning.
>
> Cc: stable@vger.kernel.org
> Fixes: 692d97c380c6 ("kconfig: new configuration interface (nconfig)")
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> scripts/kconfig/nconf.gui.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
> index 7206437e784a..ec021ebd2c52 100644
> --- a/scripts/kconfig/nconf.gui.c
> +++ b/scripts/kconfig/nconf.gui.c
> @@ -175,8 +175,9 @@ void fill_window(WINDOW *win, const char *text)
> for (i = 0; i < total_lines; i++) {
> char tmp[x+10];
> const char *line = get_line(text, i);
> - int len = get_line_length(line);
> - strncpy(tmp, line, min(len, x));
> + int len = min(get_line_length(line), x);
> +
> + strncpy(tmp, line, len);
> tmp[len] = '\0';
> mvwprintw(win, i, 0, "%s", tmp);
> }
Is there a rationale behind the choice to avoid to use snprintf()
in these circumstance?
Preferring snprintf() you will not have to take care to
compute the position of the NULL terminating character of the
string, it's done automatically by this function.
Best regards,
--
Franco Martelli
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window()
2025-08-11 12:51 ` Franco Martelli
@ 2025-08-11 15:08 ` Thorsten Blum
2025-08-11 16:19 ` Thorsten Blum
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2025-08-11 15:08 UTC (permalink / raw)
To: Franco Martelli
Cc: Masahiro Yamada, Randy Dunlap, Nicolas Schier, Shankari Anand,
nir.tzachar@gmail.com, Michal Marek, stable, linux-kbuild,
linux-kernel
On 11. Aug 2025, at 14:51, Franco Martelli wrote:
> Is there a rationale behind the choice to avoid to use snprintf()
> in these circumstance?
> Preferring snprintf() you will not have to take care to
> compute the position of the NULL terminating character of the
> string, it's done automatically by this function.
I looked into it a bit more and I think we need neither strncpy() nor
snprintf() (and no temporary buffer) because this should be sufficient:
mvwprintw(win, i, 0, "%.*s", len, line);
Unless I'm missing something, I'm happy to send a v2.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window()
2025-08-11 15:08 ` Thorsten Blum
@ 2025-08-11 16:19 ` Thorsten Blum
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2025-08-11 16:19 UTC (permalink / raw)
To: Franco Martelli
Cc: Masahiro Yamada, Randy Dunlap, Nicolas Schier, Shankari Anand,
nir.tzachar@gmail.com, Michal Marek, stable, linux-kbuild,
linux-kernel
On 11. Aug 2025, at 17:08, Thorsten Blum wrote:
> On 11. Aug 2025, at 14:51, Franco Martelli wrote:
>> Is there a rationale behind the choice to avoid to use snprintf()
>> in these circumstance?
>> Preferring snprintf() you will not have to take care to
>> compute the position of the NULL terminating character of the
>> string, it's done automatically by this function.
>
> I looked into it a bit more and I think we need neither strncpy() nor
> snprintf() (and no temporary buffer) because this should be sufficient:
>
> mvwprintw(win, i, 0, "%.*s", len, line);
>
> Unless I'm missing something, I'm happy to send a v2.
I submitted this as a new patch instead of a v2:
https://lore.kernel.org/lkml/20250811161650.37428-2-thorsten.blum@linux.dev/
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-11 16:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 14:22 [PATCH] kconfig: nconf: NUL-terminate 'line' correctly in fill_window() Thorsten Blum
2025-08-11 0:19 ` Randy Dunlap
2025-08-11 12:51 ` Franco Martelli
2025-08-11 15:08 ` Thorsten Blum
2025-08-11 16:19 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox