From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IqVeZ-000757-3s for mharc-grub-devel@gnu.org; Fri, 09 Nov 2007 10:20:15 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IqVeW-00073k-RK for grub-devel@gnu.org; Fri, 09 Nov 2007 10:20:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IqVeU-0006zp-6E for grub-devel@gnu.org; Fri, 09 Nov 2007 10:20:12 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IqVeU-0006zj-3w for grub-devel@gnu.org; Fri, 09 Nov 2007 10:20:10 -0500 Received: from smtp-vbr2.xs4all.nl ([194.109.24.22]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IqVeT-0004TZ-PK for grub-devel@gnu.org; Fri, 09 Nov 2007 10:20:10 -0500 Received: from localhost.localdomain (249-174.surfsnel.dsl.internl.net [145.99.174.249]) by smtp-vbr2.xs4all.nl (8.13.8/8.13.8) with ESMTP id lA9FK8dW052999 for ; Fri, 9 Nov 2007 16:20:09 +0100 (CET) (envelope-from mgerards@xs4all.nl) From: Marco Gerards To: The development of GRUB 2 References: <473230F2.6040305@t-online.de> Mail-Copies-To: mgerards@xs4all.nl Date: Fri, 09 Nov 2007 16:20:39 +0100 In-Reply-To: <473230F2.6040305@t-online.de> (Christian Franke's message of "Wed, 07 Nov 2007 22:41:06 +0100") Message-ID: <87ejezla2g.fsf@xs4all.nl> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 Subject: Re: [PATCH] Avoid crash on empty menu X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Nov 2007 15:20:13 -0000 Christian Franke writes: > If grub.cfg does not contain any valid menuentry statements, an empty > menu is opened. > grub-emu crashes (and real grub behaves "interesting") if the first > entry is selected. > > The attached patch adds the missing nullptr checks. > > An alternative would be to treat an empty menu as a syntax error in > main.c::read_config_file(), at least if !nested. Right, perhaps. But for now this is sufficient as it fixes a very annoying bug :-) > During testing, I found the following issues: > > - If the file does not exist, read_config_file() produces a memory > leak, because newmenu is allocated first. > > - The commands "source FILE" and "configfile FILE" open a nested > normal mode shell (and produce this leak) if the file is missing. An > error message should IMO be printed instead. > > - The sequence "c" -> "rescue" -> "normal" appends the same entries to > the existing menu, because the old entry is reused from "menu" data > slot. > > Thanks for any comment. > > Christian > > 2007-11-07 Christian Franke > > * normal/menu.c (menu_run): Check for empty menu to avoid crash. > (grub_run_menu): Likewise. > > > --- grub2.orig/normal/menu.c 2007-08-20 16:35:20.000000000 +0200 > +++ grub2/normal/menu.c 2007-11-07 21:57:44.375000000 +0100 > @@ -412,7 +412,11 @@ run_menu (grub_menu_t menu, int nested) > goto refresh; > > case 'e': > - grub_menu_entry_run (get_entry (menu, first + offset)); > + { > + grub_menu_entry_t e = get_entry (menu, first + offset); > + if (e) > + grub_menu_entry_run (e); > + } > goto refresh; > > default: > @@ -451,10 +455,13 @@ grub_menu_run (grub_menu_t menu, int nes > if (boot_entry < 0) > break; > > + e = get_entry (menu, boot_entry); > + if (! e) > + continue; /* menu is empty */ Please use proper interpunctions for comments. > grub_cls (); > grub_setcursor (1); > > - e = get_entry (menu, boot_entry); > grub_printf (" Booting \'%s\'\n\n", e->title); > > run_menu_entry (e); -- Marco