From patchwork Tue May 21 08:54:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Gouders X-Patchwork-Id: 2596551 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 20770DFE75 for ; Tue, 21 May 2013 08:54:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753831Ab3EUIyP (ORCPT ); Tue, 21 May 2013 04:54:15 -0400 Received: from mx10.gouders.net ([89.244.147.155]:42700 "EHLO mx10.gouders.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752862Ab3EUIyN (ORCPT ); Tue, 21 May 2013 04:54:13 -0400 Received: from mx10.gouders.net (localhost [127.0.0.1]) by mx10.gouders.net (8.14.6/8.14.5) with ESMTP id r4L8sBrD011970 for ; Tue, 21 May 2013 10:54:11 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gouders.net; s=gnet; t=1369126451; bh=IYTo/o4QaX0Bh3hya9VhOWoGe81bD0e31oOsSf1t1hQ=; h=From:To:Subject:Date; b=dSuXAaKN61gLALtOQJ1dJEakicKRpdqrVJfP0McpaTiNlKI5nHlokqnS6NpnXCzn+ hrQJoDAOHA9HkGgc09QIzwJ1ysmdjO0L5q7ujE3oeNnASQCJJo3wj6QBBG56zXBCZ0 kE0bSY5BOJmPjJypLZRu7oE4U/C3iN0VHZvf60vY= From: Dirk Gouders To: linux-kbuild@vger.kernel.org Subject: [PATCH] kconfig/menu.c: fix multiple references to expressions in menu_add_prop() Date: Tue, 21 May 2013 10:54:11 +0200 Message-Id: <1369126451-11930-1-git-send-email-dirk@gouders.net> X-Mailer: git-send-email 1.8.2.1 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org 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 --- 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); } }