Skip to content

Commit 7a263a0

Browse files
committed
kconfig: fix segmentation fault in menuconfig search
Since commit d05377e ("kconfig: Create links to main menu items in search"), menuconfig shows a jump key next to "Main menu" if the nearest visible parent is the rootmenu. If you press that jump key, menuconfig crashes with a segmentation fault. For example, do this: $ make ARCH=arm64 allnoconfig menuconfig Press '/' to search for the string "ACPI". Press '1' to choose "(1) Main menu". Then, menuconfig crashed with a segmentation fault. The following code in search_conf() conf(targets[i]->parent, targets[i]); results in NULL pointer dereference because targets[i] is the rootmenu, which does not have a parent. Commit d05377e tried to fix the issue of top-level items not having a jump key, but adding the "Main menu" was not the right fix. The correct fix is to show the searched item itself. This fixes another weird behavior described in the comment block. Fixes: d05377e ("kconfig: Create links to main menu items in search") Reported-by: Johannes Zink <j.zink@pengutronix.de> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Bagas Sanjaya <bagasdotme@gmail.com> Tested-by: Johannes Zink <j.zink@pengutronix.de>
1 parent fb3041d commit 7a263a0

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

scripts/kconfig/menu.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
722722
if (!expr_eq(prop->menu->dep, prop->visible.expr))
723723
get_dep_str(r, prop->visible.expr, " Visible if: ");
724724

725-
menu = prop->menu->parent;
726-
for (i = 0; menu && i < 8; menu = menu->parent) {
725+
menu = prop->menu;
726+
for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) {
727727
bool accessible = menu_is_visible(menu);
728728

729729
submenu[i++] = menu;
@@ -733,16 +733,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
733733
if (head && location) {
734734
jump = xmalloc(sizeof(struct jump_key));
735735

736-
if (menu_is_visible(prop->menu)) {
737-
/*
738-
* There is not enough room to put the hint at the
739-
* beginning of the "Prompt" line. Put the hint on the
740-
* last "Location" line even when it would belong on
741-
* the former.
742-
*/
743-
jump->target = prop->menu;
744-
} else
745-
jump->target = location;
736+
jump->target = location;
746737

747738
if (list_empty(head))
748739
jump->index = 0;
@@ -758,13 +749,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
758749
menu = submenu[i];
759750
if (jump && menu == location)
760751
jump->offset = strlen(r->s);
761-
762-
if (menu == &rootmenu)
763-
/* The real rootmenu prompt is ugly */
764-
str_printf(r, "%*cMain menu", j, ' ');
765-
else
766-
str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu));
767-
752+
str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu));
768753
if (menu->sym) {
769754
str_printf(r, " (%s [=%s])", menu->sym->name ?
770755
menu->sym->name : "<choice>",

0 commit comments

Comments
 (0)