]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: readlinkat: allow pathname to be empty
authorKen Brown <kbrown@cornell.edu>
Fri, 27 Dec 2019 22:17:35 +0000 (17:17 -0500)
committerKen Brown <kbrown@cornell.edu>
Fri, 17 Jan 2020 15:27:48 +0000 (10:27 -0500)
Following Linux, allow the pathname argument to be an empty string,
provided the dirfd argument refers to a symlink opened with
O_PATH | O_NOFOLLOW.  The readlinkat call then operates on that
symlink.

winsup/cygwin/syscalls.cc

index 038a316db2fada336e34a48905a7fbdfa6870963..282d9e0ee144be59eedff153a3522627addf121f 100644 (file)
@@ -4979,8 +4979,23 @@ readlinkat (int dirfd, const char *__restrict pathname, char *__restrict buf,
   __try
     {
       char *path = tp.c_get ();
-      if (gen_full_path_at (path, dirfd, pathname))
-       __leave;
+      int res = gen_full_path_at (path, dirfd, pathname);
+      if (res)
+       {
+         if (errno != ENOENT)
+           __leave;
+         /* pathname is an empty string.  This is OK if dirfd refers
+            to a symlink that was opened with O_PATH | O_NOFOLLOW.
+            In this case, readlinkat operates on the symlink. */
+         cygheap_fdget cfd (dirfd);
+         if (cfd < 0)
+           __leave;
+         if (!(cfd->issymlink ()
+               && cfd->get_flags () & O_PATH
+               && cfd->get_flags () & O_NOFOLLOW))
+           __leave;
+         strcpy (path, cfd->get_name ());
+       }
       return readlink (path, buf, bufsize);
     }
   __except (EFAULT) {}
This page took 0.032562 seconds and 5 git commands to generate.