From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7856) id 3F4E03858D28; Tue, 23 Nov 2021 19:20:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F4E03858D28 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Xi Ruoyao To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5477] fixincludes: don't abort() on access failure [PR103306] X-Act-Checkin: gcc X-Git-Author: Xi Ruoyao X-Git-Refname: refs/heads/master X-Git-Oldrev: d6024c85a1ce568f874afa1d9431c43eccba2f59 X-Git-Newrev: 3363022ed810a2797c47867890547c8f73163257 Message-Id: <20211123192027.3F4E03858D28@sourceware.org> Date: Tue, 23 Nov 2021 19:20:27 +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: Tue, 23 Nov 2021 19:20:27 -0000 https://gcc.gnu.org/g:3363022ed810a2797c47867890547c8f73163257 commit r12-5477-g3363022ed810a2797c47867890547c8f73163257 Author: Xi Ruoyao Date: Thu Nov 18 18:46:12 2021 +0800 fixincludes: don't abort() on access failure [PR103306] 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(). Diff: --- 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);