OSDN Git Service

Backported from mainline
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Feb 2012 17:16:19 +0000 (17:16 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Feb 2012 17:16:19 +0000 (17:16 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@184050 138bc75d-0d04-0410-961f-82ee72b054a4

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

index fb2b734..f797ce9 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 4553a71..897ac51 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)