From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 1C3F13858414; Mon, 29 Nov 2021 00:43:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C3F13858414 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5568] Fix PR 19089: Environment variable TMP may yield gcc: abort X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 2f0dd172bc63555457cda42c31e9b19f280dd40a X-Git-Newrev: 68332ab7ec58a89660db82569c5f4c2251d59741 Message-Id: <20211129004320.1C3F13858414@sourceware.org> Date: Mon, 29 Nov 2021 00:43:20 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Nov 2021 00:43:20 -0000 https://gcc.gnu.org/g:68332ab7ec58a89660db82569c5f4c2251d59741 commit r12-5568-g68332ab7ec58a89660db82569c5f4c2251d59741 Author: Andrew Pinski 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. Diff: --- libiberty/make-temp-file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libiberty/make-temp-file.c b/libiberty/make-temp-file.c index 31f87fbcfde..948f10ae058 100644 --- a/libiberty/make-temp-file.c +++ b/libiberty/make-temp-file.c @@ -39,6 +39,10 @@ Boston, MA 02110-1301, USA. */ #if defined(_WIN32) && !defined(__CYGWIN__) #include #endif +#if HAVE_SYS_STAT_H +#include +#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; }