URL: <http://savannah.gnu.org/bugs/?28422>
Summary: [util/misc.c] realpath(path, NULL) leads to segfault Project: GNU GRUB Submitted by: gsutre Submitted on: Mon 28 Dec 2009 12:56:47 AM GMT Category: Compilation Severity: Major Priority: 5 - Normal Item Group: Software Error Status: None Privacy: Public Assigned to: None Originator Name: Originator Email: Open/Closed: Open Discussion Lock: Any Release: Release: Bazaar - trunk Reproducibility: Every Time Planned Release: None _______________________________________________________ Details: Hi, On NetBSD 5.0, grub-mkrelpath segfaults due to a call to realpath of the form realpath (path, NULL) in make_system_path_relative_to_its_root (file util/misc.c). The following patch solves the problem, but a better option might be to use some autoconf macros? Thanks for your work, Gregoire --- util/misc.c.orig 2009-12-28 01:09:18.000000000 +0100 +++ util/misc.c @@ -52,6 +52,19 @@ #include <winioctl.h> #endif +/* Determine compile-time limit for realpath(). */ +#include <limits.h> +#include <sys/param.h> +#if defined(PATH_MAX) +# define REALPATH_MAX PATH_MAX +#elif defined(MAXPATHLEN) +# define REALPATH_MAX MAXPATHLEN +#else +# warning "No compile-time limit found for realpath(). Using 1024." +# define REALPATH_MAX 1024 +#endif + + int verbosity = 0; void @@ -490,14 +503,10 @@ make_system_path_relative_to_its_root (c size_t len; /* canonicalize. */ - p = realpath (path, NULL); - - if (p == NULL) + p = (char *) xmalloc (REALPATH_MAX); + if (realpath (path, p) == NULL) { - if (errno != EINVAL) - grub_util_error ("failed to get realpath of %s", path); - else - grub_util_error ("realpath not supporting (path, NULL)"); + grub_util_error ("failed to get realpath of %s", path); } len = strlen (p) + 1; buf = strdup (p); _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?28422> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/ _______________________________________________ Bug-grub mailing list Bug-grub@gnu.org http://lists.gnu.org/mailman/listinfo/bug-grub