]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kconfig: nconf: Ensure null termination where strncpy is used
authorShankari Anand <shankari.ak0208@gmail.com>
Wed, 25 Jun 2025 19:06:54 +0000 (00:36 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:28:29 +0000 (16:28 +0200)
[ Upstream commit f468992936894c9ce3b1659cf38c230d33b77a16 ]

strncpy() does not guarantee null-termination if the source string is
longer than the destination buffer.

Ensure the buffer is explicitly null-terminated to prevent potential
string overflows or undefined behavior.

Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Nicolas Schier <n.schier@avm.de>
Acked-by: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
scripts/kconfig/nconf.c
scripts/kconfig/nconf.gui.c

index 8cd72fe259740583f76701a6be4445f7d366417f..7a17c94a1594189f4ae60c6a9feb984e06896325 100644 (file)
@@ -591,6 +591,8 @@ static void item_add_str(const char *fmt, ...)
                tmp_str,
                sizeof(k_menu_items[index].str));
 
+       k_menu_items[index].str[sizeof(k_menu_items[index].str) - 1] = '\0';
+
        free_item(curses_menu_items[index]);
        curses_menu_items[index] = new_item(
                        k_menu_items[index].str,
index 25a7263ef3c8c586f0c199f0c5a0d3aef1292193..5f13a0a7fb0becc16582a5a4425c5ee8bae74360 100644 (file)
@@ -349,6 +349,7 @@ int dialog_inputbox(WINDOW *main_window,
        x = (columns-win_cols)/2;
 
        strncpy(result, init, *result_len);
+       result[*result_len - 1] = '\0';
 
        /* create the windows */
        win = newwin(win_lines, win_cols, y, x);