public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1.1] realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996]
@ 2022-03-30  4:35 Siddhesh Poyarekar
  2022-03-31 14:44 ` Andreas Schwab
  0 siblings, 1 reply; 2+ messages in thread
From: Siddhesh Poyarekar @ 2022-03-30  4:35 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella, Iker Pedrosa

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>
---
 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",
-- 
2.35.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1.1] realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996]
  2022-03-30  4:35 [PATCH v1.1] realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996] Siddhesh Poyarekar
@ 2022-03-31 14:44 ` Andreas Schwab
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2022-03-31 14:44 UTC (permalink / raw)
  To: Siddhesh Poyarekar via Libc-alpha; +Cc: Siddhesh Poyarekar, Iker Pedrosa

On Mär 30 2022, Siddhesh Poyarekar via Libc-alpha wrote:

> 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.

Ok.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-31 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30  4:35 [PATCH v1.1] realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996] Siddhesh Poyarekar
2022-03-31 14:44 ` Andreas Schwab

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).