]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR 19089: Environment variable TMP may yield gcc: abort
authorAndrew Pinski <apinski@marvell.com>
Sun, 28 Nov 2021 02:16:50 +0000 (18:16 -0800)
committerAndrew Pinski <apinski@marvell.com>
Mon, 29 Nov 2021 00:42:45 +0000 (00:42 +0000)
Even though I cannot reproduce the ICE any more, this is still
a bug. We check already to see if we can access the directory
but never check to see if the path is actually a directory.

This adds the check and now we reject the file as not usable
as a tmp directory.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

libiberty/ChangeLog:

* make-temp-file.c (try_dir): Check to see if the dir
is actually a directory.

libiberty/make-temp-file.c

index 31f87fbcfdeb3a9e978b97c5330d319821f7d314..948f10ae0587d396b4c6419cac94e5e6640bec7e 100644 (file)
@@ -39,6 +39,10 @@ Boston, MA 02110-1301, USA.  */
 #if defined(_WIN32) && !defined(__CYGWIN__)
 #include <windows.h>
 #endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
 
 #ifndef R_OK
 #define R_OK 4
@@ -76,7 +80,17 @@ try_dir (const char *dir, const char *base)
     return base;
   if (dir != 0
       && access (dir, R_OK | W_OK | X_OK) == 0)
-    return dir;
+    {
+      /* Check to make sure dir is actually a directory. */
+#ifdef S_ISDIR
+      struct stat s;
+      if (stat (dir, &s))
+       return NULL;
+      if (!S_ISDIR (s.st_mode))
+       return NULL;
+#endif
+      return dir;
+    }
   return 0;
 }