Message ID | 1638067751-28721-1-git-send-email-apinski@marvell.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 <patchwork@sourceware.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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: <gcc-patches@gcc.gnu.org> 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 Content-Type: text/plain 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: apinski--- via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: apinski@marvell.com Cc: Andrew Pinski <apinski@marvell.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
Fix PR 19089: Environment variable TMP may yield gcc: abort
|
|
Commit Message
Li, Pan2 via Gcc-patches
Nov. 28, 2021, 2:49 a.m. UTC
From: Andrew Pinski <apinski@marvell.com>
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(-)
Comments
On 11/27/2021 7:49 PM, apinski--- via Gcc-patches wrote: > From: Andrew Pinski <apinski@marvell.com> > > 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 <windows.h> > #endif > +#if HAVE_SYS_STAT_H > +#include <sys/stat.h> > +#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)) Formatting nit, missing whitespace between stat and open paren. Presumably this doesn't fix the problem in the case where S_ISDIR is not defined. But it's still an improvement. OK with the nit fixed. jeff
On Sun, Nov 28, 2021 at 12:14 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 11/27/2021 7:49 PM, apinski--- via Gcc-patches wrote: > > From: Andrew Pinski <apinski@marvell.com> > > > > 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 <windows.h> > > #endif > > +#if HAVE_SYS_STAT_H > > +#include <sys/stat.h> > > +#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)) > Formatting nit, missing whitespace between stat and open paren. > > Presumably this doesn't fix the problem in the case where S_ISDIR is not > defined. But it's still an improvement. OK with the nit fixed. Correct, though I don't know of any host where S_ISDIR is not defined. Mingw has them defined. So does cygwin. glibc (and all libc on Linux) has them defined, Solaris and AIX has them defined. So Does Mac OS X. MSVC does not define them but we don't support MSVC to compile GCC so that should not be an issue. Thanks, Andrew > > jeff >
On Mon, Nov 29, 2021 at 1:42 AM Andrew Pinski via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > On Sun, Nov 28, 2021 at 12:14 PM Jeff Law via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > > > > > On 11/27/2021 7:49 PM, apinski--- via Gcc-patches wrote: > > > From: Andrew Pinski <apinski@marvell.com> > > > > > > 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 <windows.h> > > > #endif > > > +#if HAVE_SYS_STAT_H > > > +#include <sys/stat.h> > > > +#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)) I wonder if we can instead do access (dir "/.") or so where access should complain with ENOTDIR since 'dir' isn't a directory? Richard. > > Formatting nit, missing whitespace between stat and open paren. > > > > Presumably this doesn't fix the problem in the case where S_ISDIR is not > > defined. But it's still an improvement. OK with the nit fixed. > > Correct, though I don't know of any host where S_ISDIR is not defined. > Mingw has them defined. So does cygwin. glibc (and all libc on Linux) > has them defined, Solaris and AIX has them defined. So Does Mac OS X. > > > MSVC does not define them but we don't support MSVC to compile GCC so > that should not be an issue. > > Thanks, > Andrew > > > > > jeff > >
On Mon, Nov 29, 2021 at 9:53 AM Richard Biener <richard.guenther@gmail.com> wrote: > > On Mon, Nov 29, 2021 at 1:42 AM Andrew Pinski via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > On Sun, Nov 28, 2021 at 12:14 PM Jeff Law via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > > > > > > > > > > > > On 11/27/2021 7:49 PM, apinski--- via Gcc-patches wrote: > > > > From: Andrew Pinski <apinski@marvell.com> > > > > > > > > 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 <windows.h> > > > > #endif > > > > +#if HAVE_SYS_STAT_H > > > > +#include <sys/stat.h> > > > > +#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)) > > I wonder if we can instead do access (dir "/.") or so where access > should complain with ENOTDIR since 'dir' isn't a directory? On Linux it is enough to add DIR_SEPARATOR to 'dir' passed to access. One would have to check other OSes (if they maybe fail to correctly handle trailing DIR_SEPARATOR at all). > > Richard. > > > > Formatting nit, missing whitespace between stat and open paren. > > > > > > Presumably this doesn't fix the problem in the case where S_ISDIR is not > > > defined. But it's still an improvement. OK with the nit fixed. > > > > Correct, though I don't know of any host where S_ISDIR is not defined. > > Mingw has them defined. So does cygwin. glibc (and all libc on Linux) > > has them defined, Solaris and AIX has them defined. So Does Mac OS X. > > > > > > MSVC does not define them but we don't support MSVC to compile GCC so > > that should not be an issue. > > > > Thanks, > > Andrew > > > > > > > > jeff > > >
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 <windows.h> #endif +#if HAVE_SYS_STAT_H +#include <sys/stat.h> +#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; }