]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Fix O_DIRECTORY | O_NOFOLLOW
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 18 Mar 2018 18:43:04 +0000 (19:43 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 18 Mar 2018 18:43:04 +0000 (19:43 +0100)
Appending / to the path to be looked up would make us always follow a final
symlink, even with O_NOTRANS (since the final resolution is after the
'/').  In the O_DIRECTORY | O_NOFOLLOW case, we thus have to really open
the node and stat it, which we already do anyway, and check for
directory type.

* hurd/hurdlookup.c (__hurd_file_name_lookup): Do not append '/' to
path when flags contains O_NOFOLLOW.
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR
if flags contains O_DIRECTORY and the result is a directory.

ChangeLog
hurd/hurdlookup.c
hurd/lookup-retry.c

index 82ddda54bad1ebb029c9ca10162e30e1ce3b6b35..a02f9017deb6936957fc9cb3d9976988957e97c7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * sysdeps/mach/hurd/cthreads.c: Include <cthreads.h>.
        * hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ELOOP
        when opening a symlink with O_NOFOLLOW.
+       * hurd/hurdlookup.c (__hurd_file_name_lookup): Do not append '/' to
+       path when flags contains O_NOFOLLOW.
+       * hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR
+       if flags contains O_DIRECTORY and the result is a directory.
 
 2018-03-17  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
index 1861d5879db9402e094b25df40d0036f17bfe55c..a642c4900240785adb85ff7a382a0b67a434cda4 100644 (file)
@@ -72,7 +72,7 @@ __hurd_file_name_lookup (error_t (*use_init_port)
   if (flags & O_NOFOLLOW)      /* See lookup-retry.c about O_NOFOLLOW.  */
     flags |= O_NOTRANS;
 
-  if (flags & O_DIRECTORY)
+  if (flags & O_DIRECTORY && (flags & O_NOFOLLOW) == 0)
     {
       /* The caller wants to require that the file we look up is a directory.
         We can do this without an extra RPC by appending a trailing slash
index 12b5c30962c6597ff2904c86eea5d1b4b3bf6548..b5968486242b213b47760d8f21e5a926fd9fbdca 100644 (file)
@@ -147,6 +147,8 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
                  err = __io_stat (*result, &st);
                  if (!err)
                    {
+                     if (flags & O_DIRECTORY && !S_ISDIR (st.st_mode))
+                       err = ENOTDIR;
                      if (S_ISLNK (st.st_mode))
                        err = ELOOP;
                      else if (st.st_mode & (S_IPTRANS|S_IATRANS))