public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996] Date: Thu, 31 Mar 2022 16:32:49 +0000 (GMT) [thread overview] Message-ID: <20220331163249.1AE2A3858D3C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b416555431b47a21a855f225c6f5368ae4e4d56c commit b416555431b47a21a855f225c6f5368ae4e4d56c Author: Siddhesh Poyarekar <siddhesh@sourceware.org> Date: Thu Mar 31 22:00:58 2022 +0530 realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996] The GNU extension for realpath states that if the path resolution fails with ENOENT or EACCES and the resolved buffer is non-NULL, it will contain part of the path that failed resolution. commit 949ad78a189194048df8a253bb31d1d11d919044 broke this when it omitted the copy on failure. Bring it back partially to continue supporting this GNU extension. Resolves: BZ #28996 Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Andreas Schwab <schwab@linux-m68k.org> Diff: --- stdlib/canonicalize.c | 9 ++++++--- stdlib/test-canon.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 6237a41d42..e6566bd7d9 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -400,11 +400,14 @@ realpath_stk (const char *name, char *resolved, error: *dest++ = '\0'; - if (!failed && resolved != NULL) + if (resolved != NULL) { - if (dest - rname <= get_path_max ()) + /* Copy the full result on success or partial result if failure was due + to the path not existing or not being accessible. */ + if ((!failed || errno == ENOENT || errno == EACCES) + && dest - rname <= get_path_max ()) rname = strcpy (resolved, rname); - else + else if (!failed) { failed = true; __set_errno (ENAMETOOLONG); diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c index 2ad1218749..a9c83be17c 100644 --- a/stdlib/test-canon.c +++ b/stdlib/test-canon.c @@ -174,8 +174,8 @@ do_test (int argc, char ** argv) continue; } - /* Only on success verify that buf contains the result too. */ - if (result != NULL + /* Verify buf contents if the call succeeded or failed with ENOENT. */ + if ((result != NULL || errno == ENOENT) && !check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved)) { printf ("%s: flunked test %d (expected resolved `%s', got `%s')\n",
reply other threads:[~2022-03-31 16:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220331163249.1AE2A3858D3C@sourceware.org \ --to=siddhesh@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).