]> www.infradead.org Git - users/jedix/linux-maple.git/commit
kconfig: nconf: fix core dump when searching in empty menu
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 10 Apr 2021 06:52:46 +0000 (15:52 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 12 Apr 2021 00:29:14 +0000 (09:29 +0900)
commit2d316acda727864cb55835c6eb0043219e641e2c
tree803e6b77faa56264ba76c87f3093434ac158dd4d
parent1957ddc177ee0d3ff06fb36f0149b198472a2b46
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>
scripts/kconfig/nconf.c