diff options
author | Masahiro Yamada <masahiroy@kernel.org> | 2021-04-10 15:52:46 +0900 |
---|---|---|
committer | Masahiro Yamada <masahiroy@kernel.org> | 2021-04-14 15:22:49 +0900 |
commit | 1f035a52918a4c97b99c5d9f0d5023fe659bccaa (patch) | |
tree | 9418420df518d6765a747a975abc23c4c8d8fa8b /scripts | |
parent | bffbf6e2ad6a8c9fbf78f3561404527fe69ef23d (diff) | |
download | linux-stable-1f035a52918a4c97b99c5d9f0d5023fe659bccaa.tar.gz linux-stable-1f035a52918a4c97b99c5d9f0d5023fe659bccaa.tar.bz2 linux-stable-1f035a52918a4c97b99c5d9f0d5023fe659bccaa.zip |
kconfig: nconf: fix core dump when searching in empty menu
The following code in get_mext_match():
index = (index + items_num) % items_num;
... makes the program crash when items_num is zero (that is, the menu
is empty).
A menu can be empty when all the options in it are hidden by unmet
'depends on'.
For example,
menu "This menu will be empty"
config FOO
bool "foo"
depends on BROKEN
endmenu
If you visit this menu and press a '/' key and then another key, nconf
crashes with:
Floating point exception (core dumped)
When the number of items is zero, it does not make sense to search in
the menu. In this case, current_item() returns NULL, and item_index()
ERR, but get_mext_match() does not check it.
Let's make get_mext_match() just return if the menu is empty.
While I am here, change items_num from 'int' to 'unsigned int' because
it should never become negative.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/kconfig/nconf.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index e0f965529166..0fb48f171b66 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -268,7 +268,7 @@ static int mwin_max_cols; static MENU *curses_menu; static ITEM *curses_menu_items[MAX_MENU_ITEMS]; static struct mitem k_menu_items[MAX_MENU_ITEMS]; -static int items_num; +static unsigned int items_num; static int global_exit; /* the currently selected button */ static const char *current_instructions = menu_instructions; @@ -496,8 +496,12 @@ typedef enum {MATCH_TINKER_PATTERN_UP, MATCH_TINKER_PATTERN_DOWN, /* return the index of the matched item, or -1 if no such item exists */ static int get_mext_match(const char *match_str, match_f flag) { - int match_start = item_index(current_item(curses_menu)); - int index; + int match_start, index; + + /* Do not search if the menu is empty (i.e. items_num == 0) */ + match_start = item_index(current_item(curses_menu)); + if (match_start == ERR) + return -1; if (flag == FIND_NEXT_MATCH_DOWN) ++match_start; |