From a23eb008dc764028d758ef589f67aa822a2a81e1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 31 Jul 2008 18:56:35 +0000 Subject: [PATCH] mkstemps.c (mkstemps): If open failed with errno other than EEXIST, return immediately. * 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 | 8 ++++++++ libiberty/make-temp-file.c | 12 ++++++++---- libiberty/mkstemps.c | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index bf52f9eb4919..da52583c8f29 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,11 @@ +2008-07-31 Denys Vlasenko + + * 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 * maint-tool (deps): Output config.h instead of stamp-h. diff --git a/libiberty/make-temp-file.c b/libiberty/make-temp-file.c index 5e21414ad8ee..94c76d700bd6 100644 --- a/libiberty/make-temp-file.c +++ b/libiberty/make-temp-file.c @@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA. */ #include /* May get P_tmpdir. */ #include +#include #ifdef HAVE_UNISTD_H #include #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; diff --git a/libiberty/mkstemps.c b/libiberty/mkstemps.c index 6c2e472528ba..093b67af868b 100644 --- a/libiberty/mkstemps.c +++ b/libiberty/mkstemps.c @@ -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 -- 2.47.2