]> git.ipfire.org Git - thirdparty/kernel/linux.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)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 26 Jul 2025 06:31:17 +0000 (15:31 +0900)
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>
scripts/kconfig/nconf.c
scripts/kconfig/nconf.gui.c

index c0b2dabf6c894fcdf6ac1fa651e5506bb7ac1c77..ae1fe5f60327039bd4cc1c0ae47ccf09f3a26add 100644 (file)
@@ -593,6 +593,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 4bfdf8ac2a9a34d077d6ba470ff233ec947d638b..7206437e784a0a85408b45bc84d7566f4d8917a4 100644 (file)
@@ -359,6 +359,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);