From patchwork Sun Nov 28 02:49:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 48234 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42CD83858016 for ; Sun, 28 Nov 2021 02:49:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42CD83858016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638067786; bh=XgiCuRZ+uRMyWEG4Lnf3YuD8wGAhkvMW4aQ00LNTSuo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=v6XhU5cTdVYtBuUtN2sG/e8Go1GhqA0fx8/NN2KOQW8ifDS1H1e8eXDXCvIEwGHkp 3u/dPx0r1Xn+xnaA2GiHDVl/zcX46ObAIm7y8oo/mMEWF0+jqb6nesBAKkxHAA+n8C J7PCf5E2qj/kx1d2vgHLMlUeIsLud2NDN6BNStXg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 43839385840F for ; Sun, 28 Nov 2021 02:49:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 43839385840F Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AS2XqJu024369 for ; Sat, 27 Nov 2021 18:49:16 -0800 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3ckn2s9ha5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 27 Nov 2021 18:49:16 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 27 Nov 2021 18:49:14 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 27 Nov 2021 18:49:14 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 9B65D3F70C4; Sat, 27 Nov 2021 18:49:14 -0800 (PST) To: Subject: [PATCH] Fix PR 19089: Environment variable TMP may yield gcc: abort Date: Sat, 27 Nov 2021 18:49:11 -0800 Message-ID: <1638067751-28721-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: -B71ZpX2tLArLhOwuiUPYt2r4I1-0rWX X-Proofpoint-ORIG-GUID: -B71ZpX2tLArLhOwuiUPYt2r4I1-0rWX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-27_06,2021-11-25_02,2020-04-07_01 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski 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. --- 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..11eb03d12ec 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; }