All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kconfig/menu.c: fix multiple references to expressions in menu_add_prop()
@ 2013-05-21  8:54 Dirk Gouders
  2013-05-21 12:36 ` Dirk Gouders
  2013-05-23  8:28 ` Yann E. MORIN
  0 siblings, 2 replies; 6+ messages in thread
From: Dirk Gouders @ 2013-05-21  8:54 UTC (permalink / raw)
  To: linux-kbuild

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>
---
 scripts/kconfig/menu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index b5c7d90..567939c 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -143,14 +143,25 @@ struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *e
 
 		/* Apply all upper menus' visibilities to actual prompts. */
 		if(type == P_PROMPT) {
+			struct expr *dup_expr;
 			struct menu *menu = current_entry;
 
 			while ((menu = menu->parent) != NULL) {
 				if (!menu->visibility)
 					continue;
+				/*
+				 * Do not add a reference to the
+				 * menu's visibility expression but
+				 * use a copy of it.  Otherwise the
+				 * expression reduction functions
+				 * will modify expressions that have
+				 * multiple references which can
+				 * cause unwanted side-effects.
+				 */
+				dup_expr = expr_copy(menu->visibility);
+
 				prop->visible.expr
-					= expr_alloc_and(prop->visible.expr,
-							 menu->visibility);
+					= expr_alloc_and(prop->visible.expr, dup_expr);
 			}
 		}
 
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-30  3:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-21  8:54 [PATCH] kconfig/menu.c: fix multiple references to expressions in menu_add_prop() Dirk Gouders
2013-05-21 12:36 ` Dirk Gouders
2013-05-23  8:28 ` Yann E. MORIN
2013-05-23 10:25   ` Dirk Gouders
2013-05-29 21:58     ` Yann E. MORIN
2013-05-30  3:59       ` Dirk Gouders

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.