When a (bash) environment variable TMP is set to a file with execution rights 0755, gcc aborts with an internal error. E.g.: # -- bash shell -------------------------------------------------------------- $ uname -a CYGWIN_NT-5.1 DF8JLP0J 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown Cygwin $ gcc --version gcc (GCC) 3.3.1 (cygming special) Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat a.c #include <stdlib.h> #include <stdio.h> int main(int argc , char *argv[]){ printf("Ok.\n"); return 0; } $ unset TMP $ gcc -save-temps a.c $ touch /tmp/file.txt $ export TMP=/tmp/file.txt $ gcc -save-temps a.c $ chmod u+x /tmp/file.txt $ gcc -save-temps a.c $ chmod 0755 /tmp/file.txt $ gcc -save-temps a.c gcc: Internal error: Aborted (program collect2) Please submit a full bug report. See <URL:http://gcc.gnu.org/bugs.html> for instructions. ## ---------------------------------------------------------- The MAN page does not note a dependency to TMP (only TMPDIR) ist listed.
In a way this is not a bug: 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? */ if (fd == -1) abort (); /* Similarly if we can not close the file. */ if (close (fd)) abort ();
Confirmed.
I can't reproduce the crash any more but it should not be hard to fix. The problem is in make-temp-file.c where we do: static inline const char * try_dir (const char *dir, const char *base) { if (base != 0) return base; if (dir != 0 && access (dir, R_OK | W_OK | X_OK) == 0) return dir; return 0; } But we don't check to see if the dir is actually a directory.
Something like after the access check has passed: #ifdef S_ISDIR struct stat s; if (stat(dir, &s) <0) return NULL; if (!S_ISDIR (s.st_mode)) return NULL; #endif
Patch submitted: https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585591.html The only issue is hosts where S_ISDIR is not defined (I don't think there is any left but it least it will just fail like it used to).
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>: https://gcc.gnu.org/g:68332ab7ec58a89660db82569c5f4c2251d59741 commit r12-5568-g68332ab7ec58a89660db82569c5f4c2251d59741 Author: Andrew Pinski <apinski@marvell.com> Date: Sat Nov 27 18:16:50 2021 -0800 Fix PR 19089: Environment variable TMP may yield gcc: abort 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.
Fixed. Sorry it took so long in fixing this issue.