]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Fix readlink() hanging on fifo
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 14 Sep 2022 16:52:52 +0000 (18:52 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 14 Sep 2022 16:57:44 +0000 (18:57 +0200)
readlink() opens the target with O_READ to be able to read the symlink
content. When the target is actually a fifo, that would hang waiting for a
writer (caught in the coreutils testsuite). We thus have to first lookup the
target without O_READ to perform io_stat and lookout for fifos, and only
after checking the symlink type, we can re-lookup with O_READ.

sysdeps/mach/hurd/readlink.c
sysdeps/mach/hurd/readlinkat.c

index 770462714f87fb752540158649fdfbc10316574d..2d75ef77255f2b0c13b308bce13b5e086f827e45 100644 (file)
@@ -31,7 +31,7 @@ __readlink (const char *file_name, char *buf, size_t len)
   file_t file;
   struct stat64 st;
 
-  file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0);
+  file = __file_name_lookup (file_name, O_NOLINK, 0);
   if (file == MACH_PORT_NULL)
     return -1;
 
@@ -41,6 +41,9 @@ __readlink (const char *file_name, char *buf, size_t len)
       {
        char *rbuf = buf;
 
+       __mach_port_deallocate (__mach_task_self (), file);
+       file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0);
+
        err = __io_read (file, &rbuf, &len, 0, len);
        if (!err && rbuf != buf)
          {
index 059aad9f5808f27b0c3d7a314761885818ab22f5..113b92b73285d65f969cfe3fe2c9b438ff5a45be 100644 (file)
@@ -32,7 +32,7 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len)
   file_t file;
   struct stat64 st;
 
-  file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0);
+  file = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0);
   if (file == MACH_PORT_NULL)
     return -1;
 
@@ -42,6 +42,9 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len)
       {
        char *rbuf = buf;
 
+       __mach_port_deallocate (__mach_task_self (), file);
+       file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0);
+
        err = __io_read (file, &rbuf, &len, 0, len);
        if (!err && rbuf != buf)
          {