All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrej Gelenberg <andrej.gelenberg@udo.edu>
To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org
Subject: [PATCH] nconfig: prevent segfault on empty menu
Date: Sun, 10 Jul 2011 04:04:47 +0200	[thread overview]
Message-ID: <4E1908BF.4010700@udo.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

Hello,

i found and fixed an NULL-dereference bug in nconf tool.

How to reproduce:
1. $ make nconfig
2. disable "Kernel hacking -> Debug Filesystem"
3. go to "General setup -> GCOV-based kernel profiling" and hit F2
it should segfault

Fix: i have added some checks for "struct menu*" to be NULL before it
get dereferenced

Regards,
Andrej Gelenberg

[-- Attachment #2: 0001-nconfig-prevent-segfault-on-empty-menu.patch --]
[-- Type: text/plain, Size: 1882 bytes --]

>From 82be343a388a02477ffb0d464e1f2810c61a1fda Mon Sep 17 00:00:00 2001
From: Andrej Gelenberg <andrej.gelenberg@udo.edu>
Date: Sun, 10 Jul 2011 03:44:50 +0200
Subject: [PATCH] nconfig: prevent segfault on empty menu

how to reproduce:
1. $ make nconfig
2. disable "Kernel hacking -> Debug Filesystem"
3. go to "General setup -> GCOV-based kernel profiling" and hit F2
it should segfault

Fix: i have added some checks for "struct menu*" to be NULL bevor it get dereferenced

Signed-off-by: Andrej Gelenberg <andrej.gelenberg@udo.edu>
---
 scripts/kconfig/menu.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 5fdf10d..6a09cc4 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -425,7 +425,7 @@ void menu_finalize(struct menu *parent)
 
 bool menu_has_prompt(struct menu *menu)
 {
-	if (!menu->prompt)
+	if ((!menu) || (!menu->prompt))
 		return false;
 	return true;
 }
@@ -436,7 +436,7 @@ bool menu_is_visible(struct menu *menu)
 	struct symbol *sym;
 	tristate visible;
 
-	if (!menu->prompt)
+	if ((!menu) || !menu->prompt)
 		return false;
 
 	if (menu->visibility) {
@@ -470,10 +470,12 @@ bool menu_is_visible(struct menu *menu)
 
 const char *menu_get_prompt(struct menu *menu)
 {
-	if (menu->prompt)
-		return menu->prompt->text;
-	else if (menu->sym)
-		return menu->sym->name;
+	if (menu) {
+		if (menu->prompt)
+			return menu->prompt->text;
+		else if (menu->sym)
+			return menu->sym->name;
+	}
 	return NULL;
 }
 
@@ -496,12 +498,12 @@ struct menu *menu_get_parent_menu(struct menu *menu)
 
 bool menu_has_help(struct menu *menu)
 {
-	return menu->help != NULL;
+	return menu && (menu->help != NULL);
 }
 
 const char *menu_get_help(struct menu *menu)
 {
-	if (menu->help)
+	if (menu && menu->help)
 		return menu->help;
 	else
 		return "";
-- 
1.7.6


WARNING: multiple messages have this Message-ID (diff)
From: Andrej Gelenberg <andrej.gelenberg@udo.edu>
To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org
Subject: [PATCH] nconfig: prevent segfault on empty menu
Date: Sun, 10 Jul 2011 04:04:47 +0200	[thread overview]
Message-ID: <4E1908BF.4010700@udo.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

Hello,

i found and fixed an NULL-dereference bug in nconf tool.

How to reproduce:
1. $ make nconfig
2. disable "Kernel hacking -> Debug Filesystem"
3. go to "General setup -> GCOV-based kernel profiling" and hit F2
it should segfault

Fix: i have added some checks for "struct menu*" to be NULL before it
get dereferenced

Regards,
Andrej Gelenberg

[-- Attachment #2: 0001-nconfig-prevent-segfault-on-empty-menu.patch --]
[-- Type: text/plain, Size: 1881 bytes --]

From 82be343a388a02477ffb0d464e1f2810c61a1fda Mon Sep 17 00:00:00 2001
From: Andrej Gelenberg <andrej.gelenberg@udo.edu>
Date: Sun, 10 Jul 2011 03:44:50 +0200
Subject: [PATCH] nconfig: prevent segfault on empty menu

how to reproduce:
1. $ make nconfig
2. disable "Kernel hacking -> Debug Filesystem"
3. go to "General setup -> GCOV-based kernel profiling" and hit F2
it should segfault

Fix: i have added some checks for "struct menu*" to be NULL bevor it get dereferenced

Signed-off-by: Andrej Gelenberg <andrej.gelenberg@udo.edu>
---
 scripts/kconfig/menu.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 5fdf10d..6a09cc4 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -425,7 +425,7 @@ void menu_finalize(struct menu *parent)
 
 bool menu_has_prompt(struct menu *menu)
 {
-	if (!menu->prompt)
+	if ((!menu) || (!menu->prompt))
 		return false;
 	return true;
 }
@@ -436,7 +436,7 @@ bool menu_is_visible(struct menu *menu)
 	struct symbol *sym;
 	tristate visible;
 
-	if (!menu->prompt)
+	if ((!menu) || !menu->prompt)
 		return false;
 
 	if (menu->visibility) {
@@ -470,10 +470,12 @@ bool menu_is_visible(struct menu *menu)
 
 const char *menu_get_prompt(struct menu *menu)
 {
-	if (menu->prompt)
-		return menu->prompt->text;
-	else if (menu->sym)
-		return menu->sym->name;
+	if (menu) {
+		if (menu->prompt)
+			return menu->prompt->text;
+		else if (menu->sym)
+			return menu->sym->name;
+	}
 	return NULL;
 }
 
@@ -496,12 +498,12 @@ struct menu *menu_get_parent_menu(struct menu *menu)
 
 bool menu_has_help(struct menu *menu)
 {
-	return menu->help != NULL;
+	return menu && (menu->help != NULL);
 }
 
 const char *menu_get_help(struct menu *menu)
 {
-	if (menu->help)
+	if (menu && menu->help)
 		return menu->help;
 	else
 		return "";
-- 
1.7.6


             reply	other threads:[~2011-07-10  2:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-10  2:04 Andrej Gelenberg [this message]
2011-07-10  2:04 ` [PATCH] nconfig: prevent segfault on empty menu Andrej Gelenberg
2011-07-10  6:02 ` Arnaud Lacombe
2011-07-10  7:27   ` [PATCH 1/2] kconfig/nconf: use the generic menu_get_ext_help() Arnaud Lacombe
2011-07-10  7:27     ` [PATCH 2/2] kconfig/nconf: prevent segfault on empty menu Arnaud Lacombe
2011-07-10 10:32       ` Nir Tzachar
2011-07-10 16:18         ` Arnaud Lacombe
2011-07-11  6:19           ` Nir Tzachar
2011-07-11  8:51         ` Andrej Gelenberg
2011-07-11  9:50           ` Nir Tzachar
2011-07-12 20:17             ` Andrej Gelenberg
2011-07-12 20:17               ` Andrej Gelenberg
2011-07-12 20:49               ` Arnaud Lacombe
2011-07-13 11:49       ` Michal Marek
2011-07-18 18:11     ` [PATCH 1/2] kconfig/nconf: use the generic menu_get_ext_help() Arnaud Lacombe
2011-07-18 19:02       ` Arnaud Lacombe

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=4E1908BF.4010700@udo.edu \
    --to=andrej.gelenberg@udo.edu \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 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.