public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Dirk Gouders <dirk@gouders.net>
To: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Martin Walch <walch.martin@web.de>,
	linux-kbuild@vger.kernel.org, Michal Marek <mmarek@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Libo Chen <libo.chen@huawei.com>
Subject: [PATCH] scripts/kconfig: handle cases with 'option modules' defined after reference
Date: Tue, 19 Nov 2013 22:08:24 +0100	[thread overview]
Message-ID: <gh7gc414mv.fsf_-_@lena.gouders.net> (raw)
In-Reply-To: <gheh6c155v.fsf@lena.gouders.net> (Dirk Gouders's message of "Tue, 19 Nov 2013 21:57:00 +0100")

Currently, the following test-case causes a segfault:

config A
	tristate "A" if m

config MODULES
	boolean "MODULES"
	option modules

This is, because modules_sym is NULL until 'option modules' appears,
since commit
6902dccfda (kconfig: do not special-case 'MODULES' symbol).

The above example causes an expression of type symbol being generated
with NULL as the pointer to the symbol in menu_check_dep(), later
causing a segfault when that pointer is dereferenced.

This patch basically reverts commit 6902dccfda keeping only the change
that modules_sym references symbol 'n' as a default when 'option
modules' is not used in the config files.

Reported-by: Martin Walch <walch.martin@web.de>
Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 scripts/kconfig/menu.c  |  9 ++++++---
 scripts/kconfig/zconf.y | 11 +++++++++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index db1512a..c4ec1ff 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -198,15 +198,18 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
 
 void menu_add_option(int token, char *arg)
 {
+	struct property *prop;
+
 	switch (token) {
 	case T_OPT_MODULES:
-		if (modules_sym)
+		if (modules_sym->prop)
 			zconf_error("symbol '%s' redefines option 'modules'"
 				    " already defined by symbol '%s'",
 				    current_entry->sym->name,
-				    modules_sym->name
+				    prop_get_symbol(modules_sym->prop)->name
 				    );
-		modules_sym = current_entry->sym;
+		prop = prop_alloc(P_DEFAULT, modules_sym);
+		prop->expr = expr_alloc_symbol(current_entry->sym);
 		break;
 	case T_OPT_DEFCONFIG_LIST:
 		if (!sym_defconfig_list)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 0653886..941ec32 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -493,6 +493,9 @@ void conf_parse(const char *name)
 
 	sym_init();
 	_menu_init();
+	modules_sym = sym_lookup(NULL, 0);
+	modules_sym->type = S_BOOLEAN;
+	modules_sym->flags |= SYMBOL_AUTO;
 	rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
 
 	if (getenv("ZCONF_DEBUG"))
@@ -500,8 +503,12 @@ void conf_parse(const char *name)
 	zconfparse();
 	if (zconfnerrs)
 		exit(1);
-	if (!modules_sym)
-		modules_sym = sym_find( "n" );
+	if (!modules_sym->prop) {
+		struct property *prop;
+
+		prop = prop_alloc(P_DEFAULT, modules_sym);
+		prop->expr = expr_alloc_symbol(sym_find("n"));
+	}
 
 	rootmenu.prompt->text = _(rootmenu.prompt->text);
 	rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
-- 
1.8.4


  reply	other threads:[~2013-11-19 21:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-28  2:16 Segmentation Fault with 'm' Dependencies Martin Walch
2013-11-05 23:06 ` Yann E. MORIN
2013-11-19 20:57   ` Dirk Gouders
2013-11-19 21:08     ` Dirk Gouders [this message]
2013-11-19 21:39     ` Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gh7gc414mv.fsf_-_@lena.gouders.net \
    --to=dirk@gouders.net \
    --cc=akpm@linux-foundation.org \
    --cc=libo.chen@huawei.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=walch.martin@web.de \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox