Skip to content

Commit f468992

Browse files
Shankari02masahir0y
authored andcommitted
kconfig: nconf: Ensure null termination where strncpy is used
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 <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Randy Dunlap <[email protected]> Tested-by: Randy Dunlap <[email protected]> Tested-by: Nicolas Schier <[email protected]> Acked-by: Nicolas Schier <[email protected]>
1 parent 9e0bd6d commit f468992

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

scripts/kconfig/nconf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,8 @@ static void item_add_str(const char *fmt, ...)
593593
tmp_str,
594594
sizeof(k_menu_items[index].str));
595595

596+
k_menu_items[index].str[sizeof(k_menu_items[index].str) - 1] = '\0';
597+
596598
free_item(curses_menu_items[index]);
597599
curses_menu_items[index] = new_item(
598600
k_menu_items[index].str,

scripts/kconfig/nconf.gui.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ int dialog_inputbox(WINDOW *main_window,
359359
x = (columns-win_cols)/2;
360360

361361
strncpy(result, init, *result_len);
362+
result[*result_len - 1] = '\0';
362363

363364
/* create the windows */
364365
win = newwin(win_lines, win_cols, y, x);

0 commit comments

Comments
 (0)