public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gcc cannot deal with full /tmp
@ 2008-07-28 19:25 Denys Vlasenko
  2008-07-28 20:12 ` Joseph S. Myers
  2008-07-29 15:57 ` Ian Lance Taylor
  0 siblings, 2 replies; 21+ messages in thread
From: Denys Vlasenko @ 2008-07-28 19:25 UTC (permalink / raw)
  To: dj, ian; +Cc: gcc-patches, binutils

[-- Attachment #1: Type: text/plain, Size: 712 bytes --]

Hi,

This is a trivial fix for
https://bugzilla.redhat.com/show_bug.cgi?id=203231

This bug is actually in libiberty, thus I post the patch to both gcc and
binutils list.

Bug description:
mkstemps() loops TMP_MAX times even if open error is fatal. This creates
an impression that gcc hung (TMP_MAX is ~200000). Moreover, when it does
finish looping and returns to make_temp_file(), make_temp_file()
just abort()s without good error message.

The patch deals with both problems.

Sample output:

Cannot create temporary file in /root/srcdevel/gcc/testdir/: Permission denied
./z.sh: line 13:  6115 Aborted                 TMP=$PWD/testdir i486-linux-uclibc-gcc -o t t.c



Please ACK or comment. Thanks.
--
vda


[-- Attachment #2: 1.patch --]
[-- Type: text/x-diff, Size: 1666 bytes --]

diff -d -urpN gcc.0/libiberty/make-temp-file.c gcc.1/libiberty/make-temp-file.c
--- gcc.0/libiberty/make-temp-file.c	2008-07-21 14:50:00.000000000 +0200
+++ gcc.1/libiberty/make-temp-file.c	2008-07-21 16:28:06.000000000 +0200
@@ -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,12 +167,13 @@ 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 ();
+    }
   if (close (fd))
-    abort ();
+    abort (); /* sheer paranoia */
   return temp_filename;
 }
diff -d -urpN gcc.0/libiberty/mkstemps.c gcc.1/libiberty/mkstemps.c
--- gcc.0/libiberty/mkstemps.c	2008-07-21 14:50:00.000000000 +0200
+++ gcc.1/libiberty/mkstemps.c	2008-07-28 18:48:34.000000000 +0200
@@ -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

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: [PATCH] gcc cannot deal with full /tmp
@ 2008-07-31 19:59 Zack Weinberg
  2008-07-31 21:48 ` Ian Lance Taylor
  0 siblings, 1 reply; 21+ messages in thread
From: Zack Weinberg @ 2008-07-31 19:59 UTC (permalink / raw)
  To: Denys Vlasenko, GCC Patches

+      if (errno != EEXIST)
+	/* Fatal error (EPERM, ENOSPC etc).  Doesn't make sense to loop.  */
+	break;

You should also loop on EISDIR.

zw

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2008-08-18 12:35 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-28 19:25 [PATCH] gcc cannot deal with full /tmp Denys Vlasenko
2008-07-28 20:12 ` Joseph S. Myers
2008-07-28 21:22   ` Aaron W. LaFramboise
2008-07-29 15:57 ` Ian Lance Taylor
2008-07-29 16:57   ` Jakub Jelinek
2008-07-30 14:17   ` Denys Vlasenko
2008-07-30 15:12     ` Ian Lance Taylor
2008-07-31 10:30       ` Jakub Jelinek
2008-07-31 20:15         ` Ian Lance Taylor
2008-07-31 19:59 Zack Weinberg
2008-07-31 21:48 ` Ian Lance Taylor
2008-08-01 10:57   ` Denys Vlasenko
2008-08-01 21:51     ` Zack Weinberg
2008-08-04 11:03       ` Denys Vlasenko
2008-08-17  8:33         ` Zack Weinberg
2008-08-18 12:10           ` Denys Vlasenko
2008-08-18 12:29             ` Jakub Jelinek
2008-08-18 12:35               ` Denys Vlasenko
2008-08-18 13:24                 ` Andreas Schwab
2008-08-18 13:25                   ` Denys Vlasenko
2008-08-18 13:57                     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).