]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
mkstemps.c (mkstemps): If open failed with errno other than EEXIST, return immediately.
authorDenys Vlasenko <dvlasenk@redhat.com>
Thu, 31 Jul 2008 18:56:35 +0000 (18:56 +0000)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 31 Jul 2008 18:56:35 +0000 (20:56 +0200)
* mkstemps.c (mkstemps): If open failed with errno other than
EEXIST, return immediately.
* make-temp-file.c: Include errno.h.
(make_temp_file): If mkstemps failed, print an error message
before aborting.

From-SVN: r138429

libiberty/ChangeLog
libiberty/make-temp-file.c
libiberty/mkstemps.c

index bf52f9eb49191e2924c6cbf107279f32263222b4..da52583c8f29ee79ad43a98539b1920cb61aa112 100644 (file)
@@ -1,3 +1,11 @@
+2008-07-31  Denys Vlasenko  <dvlasenk@redhat.com>
+
+       * mkstemps.c (mkstemps): If open failed with errno other than
+       EEXIST, return immediately.
+       * make-temp-file.c: Include errno.h.
+       (make_temp_file): If mkstemps failed, print an error message
+       before aborting.
+
 2008-07-24  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * maint-tool (deps): Output config.h instead of stamp-h.
index 5e21414ad8eed1f8294879235c2775f13956a647..94c76d700bd6e5817f62794b1ea05f05048967a0 100644 (file)
@@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA.  */
 
 #include <stdio.h>     /* May get P_tmpdir.  */
 #include <sys/types.h>
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -166,11 +167,14 @@ make_temp_file (const char *suffix)
   strcpy (temp_filename + base_len + TEMP_FILE_LEN, suffix);
 
   fd = mkstemps (temp_filename, suffix_len);
-  /* If mkstemps failed, then something bad is happening.  Maybe we should
-     issue a message about a possible security attack in progress?  */
+  /* Mkstemps failed.  It may be EPERM, ENOSPC etc.  */
   if (fd == -1)
-    abort ();
-  /* Similarly if we can not close the file.  */
+    {
+      fprintf (stderr, "Cannot create temporary file in %s: %s\n",
+              base, strerror (errno));
+      abort ();
+    }
+  /* We abort on failed close out of sheer paranoia.  */
   if (close (fd))
     abort ();
   return temp_filename;
index 6c2e472528babdfd1da3d18afff2e7ba1beb0a2e..093b67af868baa27dc58a07e77a7abbb5f0ba434 100644 (file)
@@ -127,6 +127,9 @@ mkstemps (char *pattern, int suffix_len)
       if (fd >= 0)
        /* The file does not exist.  */
        return fd;
+      if (errno != EEXIST)
+       /* Fatal error (EPERM, ENOSPC etc).  Doesn't make sense to loop.  */
+       break;
 
       /* This is a random value.  It is only necessary that the next
         TMP_MAX values generated by adding 7777 to VALUE are different