Skip to content

Commit e983b7b

Browse files
dgoudersyann-morin-1998
authored andcommitted
kconfig/menu.c: fix multiple references to expressions in menu_add_prop()
menu_add_prop() applies upper menus' visibilities to actual prompts by AND-ing the prompts visibilities with the upper menus ones. This creates a further reference to the menu's visibilities and when the expression reduction functions do their work, they may remove or modify expressions that have multiple references, thus causing unpredictable side-effects. The following example Kconfig constructs a case where this causes problems: a menu and a prompt which's visibilities depend on the same symbol. When invoking mconf with this Kconfig and pressing "Z" we see a problem caused by a free'd expression still referenced by the menu's visibility: ------------------------------------------------------------------------ mainmenu "Kconfig Testing Configuration" config VISIBLE def_bool n config Placeholder bool "Place holder" menu "Invisible" visible if VISIBLE config TEST_VAR bool "Test option" if VISIBLE endmenu ------------------------------------------------------------------------ This patch fixes this problem by creating copies of the menu's visibility expressions before AND-ing them with the prompt's one. Signed-off-by: Dirk Gouders <[email protected]> [[email protected]: move variable into its block-scope, keep lines <80 chars, typo] Tested-by: "Yann E. MORIN" <[email protected]> Reviewed-by: "Yann E. MORIN" <[email protected]> Signed-off-by: "Yann E. MORIN" <[email protected]>
1 parent 063f466 commit e983b7b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

scripts/kconfig/menu.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,24 @@ struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *e
146146
struct menu *menu = current_entry;
147147

148148
while ((menu = menu->parent) != NULL) {
149+
struct expr *dup_expr;
150+
149151
if (!menu->visibility)
150152
continue;
153+
/*
154+
* Do not add a reference to the
155+
* menu's visibility expression but
156+
* use a copy of it. Otherwise the
157+
* expression reduction functions
158+
* will modify expressions that have
159+
* multiple references which can
160+
* cause unwanted side effects.
161+
*/
162+
dup_expr = expr_copy(menu->visibility);
163+
151164
prop->visible.expr
152165
= expr_alloc_and(prop->visible.expr,
153-
menu->visibility);
166+
dup_expr);
154167
}
155168
}
156169

0 commit comments

Comments
 (0)