From patchwork Tue Nov 23 15:39:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 48029 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 EF0C53858018 for ; Tue, 23 Nov 2021 15:42:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF0C53858018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637682144; bh=EWmhQNzdsI1STAzTSxedRx4oNgx4fr4QIdzd5KcDSyw=; h=Subject:To:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=awo7JwhWQETN8o8E4RhqD7JVHZVaQ/B0Kypv6xiM5D29G5sTARSO1C95GOYn6bjQL bdi5U1hWSS+1N/BadAVb8l3EeRxycJtMAHfh1xPdC4kP50kkfUs8kT4quCt3GkFYM0 Myrg1JnIbaWnTHpu6gToKZ7RcNGFc2iCJGxJiTPE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 1E8B93857C5E for ; Tue, 23 Nov 2021 15:39:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E8B93857C5E Received: from [IPv6:240e:35a:102a:3d00:dc73:854d:832e:2] (unknown [IPv6:240e:35a:102a:3d00:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384)) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 4065265961; Tue, 23 Nov 2021 10:39:24 -0500 (EST) Message-ID: <7207e6d39813118ec4e34937a582fdf5c64b9b0e.camel@mengyan1223.wang> Subject: [PATCH v2] fixincludes: don't abort() on access failure [PR103306] To: gcc-patches@gcc.gnu.org Date: Tue, 23 Nov 2021 23:39:20 +0800 In-Reply-To: <842e57c422ff5ee4ffcbbe3f97543d6e8beb6dc2.camel@mengyan1223.wang> References: <842e57c422ff5ee4ffcbbe3f97543d6e8beb6dc2.camel@mengyan1223.wang> User-Agent: Evolution 3.42.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3039.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, 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: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: Jakub Jelinek , Zdenek Sojka , Bruce Korb Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" [v2: format fix] Some distro may ship dangling symlinks in include directories, triggers the access failure. Skip it and continue to next header instead of being to panic. Restore to old behavior before r12-5234 but without resurrecting the problematic getcwd() call, by using the environment variable "INPUT" exported by fixinc.sh. Tested on x86_64-linux-gnu, with a dangling symlink intentionally injected into /usr/include. fixincludes/ PR bootstrap/103306 * fixincl.c (process): Don't call abort(). --- fixincludes/fixincl.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fixincludes/fixincl.c b/fixincludes/fixincl.c index a17b65866c3..92909baf85f 100644 --- a/fixincludes/fixincl.c +++ b/fixincludes/fixincl.c @@ -1352,10 +1352,19 @@ process (void) if (access (pz_curr_file, R_OK) != 0) { - /* Some really strange error happened. */ - fprintf (stderr, "Cannot access %s: %s\n", pz_curr_file, + /* It may happens if for e. g. the distro ships some broken symlinks + in /usr/include. */ + + /* "INPUT" is exported in fixinc.sh, which is the pwd where fixincl + runs. It's used instead of getcwd to avoid allocating a buffer + with unknown length. */ + const char *cwd = getenv ("INPUT"); + if (!cwd) + cwd = "the working directory"; + + fprintf (stderr, "Cannot access %s from %s: %s\n", pz_curr_file, cwd, xstrerror (errno)); - abort (); + return; } pz_curr_data = load_file (pz_curr_file);