All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Use realpath to clean up arguments to grub-probe
@ 2011-08-03  0:54 Mario Limonciello
  2011-08-15 22:30 ` Colin Watson
  0 siblings, 1 reply; 2+ messages in thread
From: Mario Limonciello @ 2011-08-03  0:54 UTC (permalink / raw)
  To: grub-devel@gnu.org; +Cc: Vladimir 'φ-coder/phcoder' Serbinenko


[-- Attachment #1.1.1: Type: text/plain, Size: 399 bytes --]

Hi,

I've found that the EFI grub-install command can fail to properly figure out devices when using the --root-directory command.  This seems to be rooted from a call to grub-probe with a ".." in the path.

This is fixed by using realpath to clean up the path passed in grub-probe.  Please see the attached patch.

Thanks,

-- 
*Mario Limonciello*
Linux Engineer
*Dell*| OS Engineering

[-- Attachment #1.1.2: Type: text/html, Size: 1429 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: realpath.patch --]
[-- Type: text/x-diff; name="realpath.patch", Size: 1210 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2011-07-26 15:19:47 +0000
+++ ChangeLog	2011-08-03 00:48:10 +0000
@@ -1,3 +1,8 @@
+2011-08-02  Mario Limonciello <mario_limonciello@dell.com>
+
+	* util/grub-probe.c: Use realpath to clean up directory arguments
+	including '..' such as that used in grub-install for EFI.
+
 2011-07-26  Colin Watson  <cjwatson@ubuntu.com>
 
 	* configure.ac: The Loongson port requires grub-mkfont due to its

=== modified file 'util/grub-probe.c'
--- util/grub-probe.c	2011-04-25 12:52:07 +0000
+++ util/grub-probe.c	2011-08-03 00:53:57 +0000
@@ -42,6 +42,9 @@
 #include <string.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
 
 #define _GNU_SOURCE	1
 #include <getopt.h>
@@ -181,7 +184,15 @@
 #endif
     }
   else
-    device_name = grub_guess_root_device (path);
+    {
+#ifdef PATH_MAX
+      grub_path = xmalloc (PATH_MAX);
+      realpath (path, grub_path);
+#else
+      grub_path = realpath(path, NULL);
+#endif
+    device_name = grub_guess_root_device (grub_path);
+    }
 
   if (! device_name)
     grub_util_error ("cannot find a device for %s (is /dev mounted?)", path);


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use realpath to clean up arguments to grub-probe
  2011-08-03  0:54 [PATCH] Use realpath to clean up arguments to grub-probe Mario Limonciello
@ 2011-08-15 22:30 ` Colin Watson
  0 siblings, 0 replies; 2+ messages in thread
From: Colin Watson @ 2011-08-15 22:30 UTC (permalink / raw)
  To: The development of GNU GRUB
  Cc: Vladimir 'φ-coder/phcoder' Serbinenko

On Tue, Aug 02, 2011 at 07:54:40PM -0500, Mario Limonciello wrote:
> I've found that the EFI grub-install command can fail to properly
> figure out devices when using the --root-directory command.  This
> seems to be rooted from a call to grub-probe with a ".." in the path.
> 
> This is fixed by using realpath to clean up the path passed in
> grub-probe.  Please see the attached patch.

This would also fix Debian bug #637768 ("grub-probe doesn't follow
symlinks").

However, there is no reason to use realpath in new code when
canonicalize_file_name exists (and is implemented more safely).  I've
adjusted your patch to the following and committed it:

=== modified file 'ChangeLog'
--- ChangeLog	2011-08-15 22:21:29 +0000
+++ ChangeLog	2011-08-15 22:28:45 +0000
@@ -1,3 +1,11 @@
+2011-08-15  Mario Limonciello  <mario_limonciello@dell.com>
+2011-08-15  Colin Watson  <cjwatson@ubuntu.com>
+
+	* util/grub-probe.c (probe): Canonicalise the path argument, fixing
+	use of "/path/.." as in grub-install for EFI as well as handling
+	symlinks correctly.
+	Fixes Debian bug #637768.
+
 2011-08-15  Colin Watson  <cjwatson@ubuntu.com>
 
 	* util/grub-probe.c: Remove duplicate #include.

=== modified file 'util/grub-probe.c'
--- util/grub-probe.c	2011-08-15 22:21:29 +0000
+++ util/grub-probe.c	2011-08-15 22:25:13 +0000
@@ -180,7 +180,10 @@ probe (const char *path, char *device_na
 #endif
     }
   else
-    device_name = grub_guess_root_device (path);
+    {
+      grub_path = canonicalize_file_name (path);
+      device_name = grub_guess_root_device (grub_path);
+    }
 
   if (! device_name)
     grub_util_error ("cannot find a device for %s (is /dev mounted?)", path);

Thanks,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-15 22:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-03  0:54 [PATCH] Use realpath to clean up arguments to grub-probe Mario Limonciello
2011-08-15 22:30 ` Colin Watson

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.