Use realpath to clean up arguments to grub-probe
PATCH 1/1 Use realpath to clean up arguments to grub-probe
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,
Signature · 3 lines
*Mario Limonciello* Linux Engineer *Dell*| OS Engineering
=== modified file 'ChangeLog'
ChangeLog +5 -0
@@ -1,3 +1,8 @@ +2011-08-02 Mario Limonciello <[email protected]> + + * 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 <[email protected]> * configure.ac: The Loongson port requires grub-mkfont due to its
=== modified file 'util/grub-probe.c'
grub-probe.c +12 -1
@@ -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);
Quoted 6 lines · Mario Limonciello
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 +8 -0
@@ -1,3 +1,11 @@ +2011-08-15 Mario Limonciello <[email protected]> +2011-08-15 Colin Watson <[email protected]> + + * 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 <[email protected]> * util/grub-probe.c: Remove duplicate #include.
=== modified file 'util/grub-probe.c'
grub-probe.c +4 -1
@@ -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,
Signature · 1 line
Colin Watson [[email protected]]