]> Savannah Git Hosting - gnulib.git/commitdiff
unlinkat: handle ignoring of ".." on Darwin 14
authorPádraig Brady <P@draigBrady.com>
Thu, 28 May 2015 13:15:08 +0000 (14:15 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 28 May 2015 16:18:37 +0000 (17:18 +0100)
* lib/unlinkat.c: unlinkat() has the same bug as unlink()
on Mac OS X 10.10, where it ignores paths with a trailing "..",
so handle in the same manner.
* m4/unlinkat.m4: Comment on this Darwin issue.
* doc/posix-functions/unlink.texi: Update the latest version
where the issue was seen.
* doc/posix-functions/unlinkat.texi: Mention this issue.
Fixes a test failure in test-unlinkat.c.

ChangeLog
doc/posix-functions/unlink.texi
doc/posix-functions/unlinkat.texi
lib/unlinkat.c
m4/unlinkat.m4

index 517d439c6809d7ddbdf603a031c3ce02e17f2a1e..035fb7aefd4cdf73fad8e7e48a029eb00850267b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-05-28  Pádraig Brady  <P@draigBrady.com>
+
+       unlinkat: handle ignoring of ".." on Darwin 14
+       * lib/unlinkat.c: unlinkat() has the same bug as unlink()
+       on Mac OS X 10.10, where it ignores paths with a trailing "..",
+       so handle in the same manner.
+       * m4/unlinkat.m4: Comment on this Darwin issue.
+       * doc/posix-functions/unlink.texi: Update the latest version
+       where the issue was seen.
+       * doc/posix-functions/unlinkat.texi: Mention this issue.
+       Fixes a test failure in test-unlinkat.c.
+
 2015-05-27  Paul Eggert  <eggert@cs.ucla.edu>
 
        qacl: split into qcopy-acl and qset-acl
index 53520a10c1da2746f37390ac6cc870bf3d54aaec..171e9facd6abc7f2eac9ea39b504eca63ff24fe0 100644 (file)
@@ -12,7 +12,7 @@ Portability problems fixed by Gnulib:
 Some systems mistakenly succeed on @code{unlink("link-to-file/")}:
 GNU/Hurd, FreeBSD 7.2, AIX 7.1, Solaris 9.
 @item
-On Mac OS X 10.5.6, in a writable HFS mount, @code{unlink("..")} succeeds
+On Mac OS X 10.10, in a writable HFS mount, @code{unlink("..")} succeeds
 without doing anything.
 @end itemize
 
index fe751b7ab42d76e5e86e8d93a6a8b79c59d381df..bfa20e6fd37f29573d6c8640292133f2e839e49e 100644 (file)
@@ -14,6 +14,9 @@ glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
 AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5, BeOS.
 But the replacement function is not safe to be used in libraries and is not multithread-safe.
 @item
+On Mac OS X 10.10, in a writable HFS mount, @code{unlinkat(fd, "..", 0)} succeeds
+without doing anything.
+@item
 Some systems mistakenly succeed on @code{unlinkat(fd,"file/",flag)}:
 GNU/Hurd, Solaris 9.
 @item
index 0d89bf97448a0249c04c1f96e6f7b7e92f7582d5..af35256fd086552b9f9f5ac142128c5206e1b82a 100644 (file)
 
 # undef unlinkat
 
-/* unlinkat without AT_REMOVEDIR does not honor trailing / on Solaris
-   9.  Solve it in a similar manner to unlink.  Hurd has the same
-   issue. */
+/* unlinkat without AT_REMOVEDIR does not honor trailing / on Solaris 9.
+   Hurd has the same issue.
+
+   unlinkat without AT_REMOVEDIR erroneously ignores ".." on Darwin 14.
+
+   Solve these in a similar manner to unlink.  */
 
 int
 rpl_unlinkat (int fd, char const *name, int flag)
@@ -78,7 +81,17 @@ rpl_unlinkat (int fd, char const *name, int flag)
         }
     }
   if (!result)
-    result = unlinkat (fd, name, flag);
+    {
+# if UNLINK_PARENT_BUG
+      if (len >= 2 && name[len - 1] == '.' && name[len - 2] == '.'
+          && (len == 2 || ISSLASH (name[len - 3])))
+        {
+          errno = EISDIR; /* could also use EPERM */
+          return -1;
+        }
+# endif
+      result = unlinkat (fd, name, flag);
+    }
   return result;
 }
 
index 6e5fa31802877bf3e77dae0f50fa846aa4721491..be70c4fefc6f9b9b64264618ccdacb04e5fbd892 100644 (file)
@@ -24,6 +24,7 @@ AC_DEFUN([gl_FUNC_UNLINKAT],
         ;;
       *)
         # GNU/Hurd has unlinkat, but it has the same bug as unlink.
+        # Darwin has unlinkat, but it has the same UNLINK_PARENT_BUG.
         if test $REPLACE_UNLINK = 1; then
           REPLACE_UNLINKAT=1
         fi