Skip to contentSkip to conversation

grub-install crash on GNU/Hurd

PATCH Samuel Thibault 2 participants 3 messages Nov 29, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

grub-install crashes on GNU/Hurd on the stat call in probe():

  if (print == PRINT_FS)
    {
      struct stat st;
      stat (path, &st);

      if (S_ISREG (st.st_mode))

because when grub-probe is passed --device /dev/hd0, path is NULL. This doesn't get noticed on Linux because it returns EFAULT instead of crashing, and by luck S_ISREG() is false.

Do people agree on the attached patch, i.e. check that the path is readable only if --device was not given?

Samuel

=== modified file 'util/grub-probe.c'

grub-probe.c +30 -27
@@ -238,33 +238,36 @@
 
   if (print == PRINT_FS)
     {
-      struct stat st;
-
-      stat (path, &st);
-
-      if (S_ISREG (st.st_mode))
-	{
-	  /* Regular file.  Verify that we can read it properly.  */
-
-	  grub_file_t file;
-	  char *rel_path;
-	  grub_util_info ("reading %s via OS facilities", path);
-	  filebuf_via_sys = grub_util_read_image (path);
-
-	  rel_path = make_system_path_relative_to_its_root (path);
-	  asprintf (&grub_path, "(%s)%s", drive_name, rel_path);
-	  free (rel_path);
-	  grub_util_info ("reading %s via GRUB facilities", grub_path);
-	  file = grub_file_open (grub_path);
-	  if (! file)
-	    grub_util_error ("can not open %s via GRUB facilities", grub_path);
-	  filebuf_via_grub = xmalloc (file->size);
-	  grub_file_read (file, filebuf_via_grub, file->size);
-
-	  grub_util_info ("comparing");
-
-	  if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
-	    grub_util_error ("files differ");
+      if (path)
+        {
+	  struct stat st;
+
+	  stat (path, &st);
+
+	  if (S_ISREG (st.st_mode))
+	    {
+	      /* Regular file.  Verify that we can read it properly.  */
+
+	      grub_file_t file;
+	      char *rel_path;
+	      grub_util_info ("reading %s via OS facilities", path);
+	      filebuf_via_sys = grub_util_read_image (path);
+
+	      rel_path = make_system_path_relative_to_its_root (path);
+	      asprintf (&grub_path, "(%s)%s", drive_name, rel_path);
+	      free (rel_path);
+	      grub_util_info ("reading %s via GRUB facilities", grub_path);
+	      file = grub_file_open (grub_path);
+	      if (! file)
+		grub_util_error ("can not open %s via GRUB facilities", grub_path);
+	      filebuf_via_grub = xmalloc (file->size);
+	      grub_file_read (file, filebuf_via_grub, file->size);
+
+	      grub_util_info ("comparing");
+
+	      if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
+		grub_util_error ("files differ");
+	    }
 	}
 
       printf ("%s\n", fs->name);
#1 lore raw

Here is the patch agains, with -w

Samuel

=== modified file 'util/grub-probe.c'

grub-probe.c +3 -0
@@ -238,6 +238,8 @@
 
   if (print == PRINT_FS)
     {
+      if (path)
+        {
       struct stat st;
 
       stat (path, &st);
@@ -266,6 +268,7 @@
 	  if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
 	    grub_util_error ("files differ");
 	}
+	}
 
       printf ("%s\n", fs->name);
     }
#2 lore raw

Am Sonntag, den 29.11.2009, 04:36 +0100 schrieb Samuel Thibault:

Quoted 3 lines

Here is the patch agains, with -w

Samuel

Looks fine to me.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer