From 26f0b0a58e84f59c7f17080951f0691ebcc6f41a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 9 Feb 2012 22:33:11 +0100 Subject: [PATCH] backport: re PR driver/48306 (presence of gcc subdir with . in PATH causes breakdown) Backported from mainline 2012-01-26 Jakub Jelinek * make-relative-prefix.c (make_relative_prefix_1): Avoid warning about using preprocessor directives inside of macro arguments. 2012-01-02 Jakub Jelinek * make-relative-prefix.c (make_relative_prefix_1): Avoid stack overflow if PATH contains just a single entry and HOST_EXECUTABLE_SUFFIX needs to be used. PR driver/48306 * make-relative-prefix.c: Include sys/stat.h. (make_relative_prefix_1): If access succeeds, check also stat if nstore is a regular file. From-SVN: r184069 --- libiberty/ChangeLog | 19 +++++++++++++++++++ libiberty/make-relative-prefix.c | 22 ++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 6742d92c9ee7..903297363421 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,22 @@ +2012-02-09 Jakub Jelinek + + Backported from mainline + 2012-01-26 Jakub Jelinek + + * make-relative-prefix.c (make_relative_prefix_1): Avoid warning + about using preprocessor directives inside of macro arguments. + + 2012-01-02 Jakub Jelinek + + * make-relative-prefix.c (make_relative_prefix_1): Avoid + stack overflow if PATH contains just a single entry and + HOST_EXECUTABLE_SUFFIX needs to be used. + + PR driver/48306 + * make-relative-prefix.c: Include sys/stat.h. + (make_relative_prefix_1): If access succeeds, check also stat + if nstore is a regular file. + 2011-08-06 Uros Bizjak * testsuite/test-expandargv.c (writeout_test): Check result of fwrite. diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c index c98d287d7c08..2fcccac38c87 100644 --- a/libiberty/make-relative-prefix.c +++ b/libiberty/make-relative-prefix.c @@ -57,6 +57,9 @@ relative prefix can be found, return @code{NULL}. #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_SYS_STAT_H +#include +#endif #include @@ -244,10 +247,15 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, { char *startp, *endp, *nstore; size_t prefixlen = strlen (temp) + 1; + size_t len; if (prefixlen < 2) prefixlen = 2; - nstore = (char *) alloca (prefixlen + strlen (progname) + 1); + len = prefixlen + strlen (progname) + 1; +#ifdef HAVE_HOST_EXECUTABLE_SUFFIX + len += strlen (HOST_EXECUTABLE_SUFFIX); +#endif + nstore = (char *) alloca (len); startp = endp = temp; while (1) @@ -262,7 +270,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, } else { - strncpy (nstore, startp, endp - startp); + memcpy (nstore, startp, endp - startp); if (! IS_DIR_SEPARATOR (endp[-1])) { nstore[endp - startp] = DIR_SEPARATOR; @@ -278,8 +286,14 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, #endif ) { - progname = nstore; - break; +#if defined (HAVE_SYS_STAT_H) && defined (S_ISREG) + struct stat st; + if (stat (nstore, &st) >= 0 && S_ISREG (st.st_mode)) +#endif + { + progname = nstore; + break; + } } if (*endp == 0) -- 2.47.2