hurd: Fix O_DIRECTORY | O_NOFOLLOW
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 14 Jan 2018 10:24:48 +0000 (10:24 +0000)
committerAurelien Jarno <aurel32@debian.org>
Sun, 14 Jan 2018 10:24:48 +0000 (10:24 +0000)
Appending / to the path to be looked up makes 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.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name tg-NOFOLLOW-DIRECTORY.diff

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

index 84cb3d301562237e43a5fec75ee3ed9f5ade773b..7d1c471b5407417a460c815c3e599f9b9279e432 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))
     {
       /* 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 4e6c765b768e5dcabe911c16bfecf07612fd34e6..bae3ec1a4e580eb8acd0c4105823d85508bec1ca 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))