]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR driver/48306 (presence of gcc subdir with . in PATH causes breakdown)
authorJakub Jelinek <jakub@redhat.com>
Thu, 9 Feb 2012 17:16:19 +0000 (18:16 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Feb 2012 17:16:19 +0000 (18:16 +0100)
Backported from mainline
2012-01-26  Jakub Jelinek  <jakub@redhat.com>

* make-relative-prefix.c (make_relative_prefix_1): Avoid warning
about using preprocessor directives inside of macro arguments.

2012-01-02  Jakub Jelinek  <jakub@redhat.com>

* 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: r184050

libiberty/ChangeLog
libiberty/make-relative-prefix.c

index fb2b7348cb45bcbf91764ff3728d4cee90757cc5..f797ce9471fcc872783bd4de38e163992afedec0 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-09  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2012-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * make-relative-prefix.c (make_relative_prefix_1): Avoid warning
+       about using preprocessor directives inside of macro arguments.
+
+       2012-01-02  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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-11-13  Iain Sandoe  <iains@gcc.gnu.org>
 
        PR target/48108
index 4553a7109d8244ec0ad572f6d5f415e7927824cf..897ac51294e0f5d26139857fe136b3b2f5b41266 100644 (file)
@@ -58,6 +58,9 @@ relative prefix can be found, return @code{NULL}.
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
 
 #include <string.h>
 
@@ -245,10 +248,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)
@@ -263,7 +271,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;
@@ -279,8 +287,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)