All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [Fwd: Re: Bug#495949: grub-common: grub-probe segfaults]
Date: Fri, 24 Jul 2009 16:33:44 -0400	[thread overview]
Message-ID: <1248467624.6620.19.camel@mj> (raw)
In-Reply-To: <1248466144.6620.16.camel@mj>

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



  reply	other threads:[~2009-07-24 20:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 18:46 [Fwd: Re: Bug#495949: grub-common: grub-probe segfaults] Felix Zielcke
2009-07-24 20:09 ` Pavel Roskin
2009-07-24 20:33   ` Pavel Roskin [this message]
2009-07-24 21:16     ` Vladimir 'phcoder' Serbinenko
2009-07-25 16:38     ` Robert Millan
2009-07-24 20:37   ` Vladimir 'phcoder' Serbinenko
2009-07-24 20:56     ` Pavel Roskin
2009-07-24 21:17       ` Vladimir 'phcoder' Serbinenko
2009-07-25 16:40         ` Robert Millan
2009-07-25  6:51     ` Felix Zielcke

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=1248467624.6620.19.camel@mj \
    --to=proski@gnu.org \
    --cc=grub-devel@gnu.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.