kconfig: nconf: Ensure null termination where strncpy is used
[ 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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
90851a290a
commit
ee777917b4
@@ -581,6 +581,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,
|
||||
|
||||
@@ -398,6 +398,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);
|
||||
|
||||
Reference in New Issue
Block a user