diff options
author | Dirk Gouders <dirk@gouders.net> | 2013-05-21 04:54:11 -0400 |
---|---|---|
committer | Yann E. MORIN <yann.morin.1998@free.fr> | 2013-05-29 18:14:01 -0400 |
commit | e983b7b17ad1a978e954e6aaa62cf12bfc747883 (patch) | |
tree | d03b6ef41719ff23f7228ce7f32c8a352b3bc070 /scripts/kconfig/menu.c | |
parent | 063f4661fde8c03c4c03f8a205071a52691c152e (diff) |
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 <dirk@gouders.net>
[yann.morin.1998@free.fr: move variable into its block-scope,
keep lines <80 chars, typo]
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Diffstat (limited to 'scripts/kconfig/menu.c')
-rw-r--r-- | scripts/kconfig/menu.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b5c7d90df9df..fd3f0180e08f 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c | |||
@@ -146,11 +146,24 @@ struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *e | |||
146 | struct menu *menu = current_entry; | 146 | struct menu *menu = current_entry; |
147 | 147 | ||
148 | while ((menu = menu->parent) != NULL) { | 148 | while ((menu = menu->parent) != NULL) { |
149 | struct expr *dup_expr; | ||
150 | |||
149 | if (!menu->visibility) | 151 | if (!menu->visibility) |
150 | continue; | 152 | 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 | |||
151 | prop->visible.expr | 164 | prop->visible.expr |
152 | = expr_alloc_and(prop->visible.expr, | 165 | = expr_alloc_and(prop->visible.expr, |
153 | menu->visibility); | 166 | dup_expr); |
154 | } | 167 | } |
155 | } | 168 | } |
156 | 169 | ||