]> 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 21:33:11 +0000 (22:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Feb 2012 21:33:11 +0000 (22:33 +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: r184069

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

index 6742d92c9ee776b294a0ed75ffbe812e61f222e4..9032973634213239d15598722b0ab8c1cd1571a7 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-08-06  Uros Bizjak  <ubizjak@gmail.com>
 
        * testsuite/test-expandargv.c (writeout_test): Check result of fwrite.
index c98d287d7c08f15779cc51b8230c66bf3e85c7a6..2fcccac38c87627f952b1775a36e757745eae4c9 100644 (file)
@@ -57,6 +57,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>
 
@@ -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)