From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MURSm-0006qQ-Qe for mharc-grub-devel@gnu.org; Fri, 24 Jul 2009 16:33:56 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MURSi-0006k3-F8 for grub-devel@gnu.org; Fri, 24 Jul 2009 16:33:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MURSd-0006bP-Jm for grub-devel@gnu.org; Fri, 24 Jul 2009 16:33:51 -0400 Received: from [199.232.76.173] (port=57847 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MURSd-0006au-9j for grub-devel@gnu.org; Fri, 24 Jul 2009 16:33:47 -0400 Received: from c60.cesmail.net ([216.154.195.49]:47401) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1MURSc-0005uV-KK for grub-devel@gnu.org; Fri, 24 Jul 2009 16:33:47 -0400 Received: from unknown (HELO smtprelay2.cesmail.net) ([192.168.1.112]) by c60.cesmail.net with ESMTP; 24 Jul 2009 16:33:45 -0400 Received: from [192.168.0.22] (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by smtprelay2.cesmail.net (Postfix) with ESMTPSA id 07B6634C6D for ; Fri, 24 Jul 2009 16:44:36 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 In-Reply-To: <1248466144.6620.16.camel@mj> References: <1248461206.3510.76.camel@fz.local> <1248466144.6620.16.camel@mj> Content-Type: text/plain Date: Fri, 24 Jul 2009 16:33:44 -0400 Message-Id: <1248467624.6620.19.camel@mj> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [Fwd: Re: Bug#495949: grub-common: grub-probe segfaults] 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, 24 Jul 2009 20:33:52 -0000 On Fri, 2009-07-24 at 16:09 -0400, Pavel Roskin wrote: > On Fri, 2009-07-24 at 20:46 +0200, Felix Zielcke wrote: > > And another bug forward > > Anyone has an idea why a dm-crypt/lvm leads to a segfault in the strcmp > > here: > > grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "pc_partition_map") ? > > find_usable_region_gpt : find_usable_region_msdos)); > > dest_partmap is only assigned a value in identify_partmap. If > grub_partition_iterate() doesn't find any partitions, dest_partmap > remains a random pointer. > > The fix would be probably to initialize dest_partmap with NULL. If it > becomes "pc_partition_map", iterate with find_usable_region_msdos, if it > becomes "gpt_partition_map", iterate with find_usable_region_gpt. If > it's NULL or another string, exit with a warning. How about this? Require positive identification of PC or GPT partition for embedding ChangeLog: * util/i386/pc/grub-setup.c (setup): Initialize dest_partmap before iteration. Don't allow embedding unless dest_partmap is "pc_partition_map" or "gpt_partition_map". --- util/i386/pc/grub-setup.c | 37 ++++++++++++++++++++++++++++++------- 1 files changed, 30 insertions(+), 7 deletions(-) diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 5a51964..7ac5ace 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -329,16 +329,39 @@ setup (const char *dir, dest_partmap = p->partmap->name; return 1; } + + dest_partmap = NULL; grub_partition_iterate (dest_dev->disk, identify_partmap); - grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "pc_partition_map") ? - find_usable_region_gpt : find_usable_region_msdos)); - if (embed_region.end == embed_region.start) + if (! dest_partmap) { - if (! strcmp (dest_partmap, "pc_partition_map")) - grub_util_warn ("This msdos-style partition label has no post-MBR gap; embedding won't be possible!"); - else - grub_util_warn ("This GPT partition label has no BIOS Boot Partition; embedding won't be possible!"); + grub_util_warn ("Cannot identify partition map."); + goto unable_to_embed; + } + else if (strcmp (dest_partmap, "pc_partition_map") == 0) + { + grub_partition_iterate (dest_dev->disk, find_usable_region_msdos); + if (embed_region.end == embed_region.start) + { + grub_util_warn ("This msdos-style partition label has no post-MBR " + "gap; embedding won't be possible!"); + goto unable_to_embed; + } + } + else if (strcmp (dest_partmap, "gpt_partition_map") == 0) + { + grub_partition_iterate (dest_dev->disk, find_usable_region_gpt); + if (embed_region.end == embed_region.start) + { + grub_util_warn ("This GPT partition label has no BIOS Boot " + "Partition; embedding won't be possible!"); + goto unable_to_embed; + } + } + else + { + grub_util_warn ("Embedding on partition type %s is unsupported", + dest_partmap); goto unable_to_embed; } -- Regards, Pavel Roskin