]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996]
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 31 Mar 2022 16:30:58 +0000 (22:00 +0530)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 20 Jan 2025 14:19:26 +0000 (15:19 +0100)
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>
(cherry picked from commit b416555431b47a21a855f225c6f5368ae4e4d56c)

NEWS
stdlib/canonicalize.c
stdlib/test-canon.c

diff --git a/NEWS b/NEWS
index 3a821a36fb773dcb41bd3fc9c32ebc626968cae1..84c070d39efb21d361a87c7948b7b8585f091c85 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,7 @@ The following bugs are resolved with this release:
     variants when avoiding overflow
   [28937] New DSO dependency sorter does not put new map first if in a cycle
   [28953] nss: Protect against errno changes in function lookup
+  [28996] realpath fails to copy partial result on ENOENT and EACCES
   [29029] nptl: poll() spuriously returns EINTR during thread
     cancellation and with cancellation disabled
   [29039] Corrupt DTV after reuse of a TLS module ID following dlclose with unused TLS
index 6237a41d42bbf9596570e7d625bbbb620ada6e1c..e6566bd7d988c45f4b2460f70f45a267eb73bcff 100644 (file)
@@ -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);
index 2ad1218749dc79e25f0b4d1947c6bfbef436eb82..a9c83be17c3ca5fdb2dcb0a99cafb946dad9d5ad 100644 (file)
@@ -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",