]> Savannah Git Hosting - gnulib.git/commitdiff
linkat: avoid OS X 10.10 trailing slash with symlink bug
authorPádraig Brady <P@draigBrady.com>
Fri, 29 May 2015 02:11:59 +0000 (03:11 +0100)
committerPádraig Brady <P@draigBrady.com>
Fri, 29 May 2015 03:05:14 +0000 (04:05 +0100)
On Darwin 14.3.0 linkat(,"path1",,"dangling_symlink/",)
causes the symlink to be dereferenced, and if it points
to a non existent file, that file will be created as
a hard link to "path1".
This fixes a test failure in test-linkat.c.

* m4/linkat.m4 (gl_FUNC_LINKAT): Augment the test with
this case.  The existing workaround in linkat.c for
trailing slash issues, suffices for this case.
* doc/posix-functions/linkat.texi: Add OS X 10.10 to
the list of platforms with trailing slash issues.

ChangeLog
doc/posix-functions/linkat.texi
m4/linkat.m4

index 035fb7aefd4cdf73fad8e7e48a029eb00850267b..82abe7f8a3d31a6fe74f110f11fb6701d987eb88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2015-05-29  Pádraig Brady  <P@draigBrady.com>
+
+       linkat: avoid OS X 10.10 trailing slash with symlink bug
+       On Darwin 14.3.0 linkat(,"path1",,"dangling_symlink/",)
+       causes the symlink to be dereferenced, and if it points
+       to a non existent file, that file will be created as
+       a hard link to "path1".
+       This fixes a test failure in test-linkat.c.
+       * m4/linkat.m4 (gl_FUNC_LINKAT): Augment the test with
+       this case.  The existing workaround in linkat.c for
+       trailing slash issues, suffices for this case.
+       * doc/posix-functions/linkat.texi: Add OS X 10.10 to
+       the list of platforms with trailing slash issues.
+
 2015-05-28  Pádraig Brady  <P@draigBrady.com>
 
        unlinkat: handle ignoring of ".." on Darwin 14
index fadb350ab51819f3e6a052116920a06339d270d4..8bdf9d378f7037166039b018675dc3f568ca783b 100644 (file)
@@ -19,7 +19,7 @@ Mac OS X 10.10.
 @item
 This function fails to reject trailing slashes on non-directories on
 some platforms:
-AIX 7.1, Solaris 11 2011-11.
+AIX 7.1, Solaris 11 2011-11, Mac OS X 10.10.
 @item
 This functions does not support @code{AT_SYMLINK_FOLLOW} on some platforms:
 Linux kernel 2.6.17.
index 567cb5dcaae9536f31a58f28a1667a6b97f5f0bc..03cf23a2e4da37d2580ac04d5e5f2d67c9a7a2f9 100644 (file)
@@ -52,7 +52,7 @@ AC_DEFUN([gl_FUNC_LINKAT],
 
     AC_CACHE_CHECK([whether linkat handles trailing slash correctly],
       [gl_cv_func_linkat_slash],
-      [rm -rf conftest.a conftest.b conftest.c conftest.d
+      [rm -rf conftest.a conftest.b conftest.c conftest.d conftest.e conftest.s
        AC_RUN_IFELSE(
          [AC_LANG_PROGRAM(
             [[#include <unistd.h>
@@ -83,6 +83,16 @@ AC_DEFUN([gl_FUNC_LINKAT],
               if (linkat (AT_FDCWD, "conftest.a", AT_FDCWD, "conftest.d/",
                           AT_SYMLINK_FOLLOW) == 0)
                 result |= 8;
+
+              /* On OS X 10.10 a trailing "/" will cause the second path to be
+                 dereferenced, and thus will succeed on a dangling symlink.  */
+              if (symlink ("conftest.e", "conftest.s") == 0)
+                {
+                  if (linkat (AT_FDCWD, "conftest.a", AT_FDCWD, "conftest.s/",
+                      AT_SYMLINK_FOLLOW) == 0)
+                    result |= 16;
+                }
+
               return result;
             ]])],
          [gl_cv_func_linkat_slash=yes],
@@ -93,7 +103,7 @@ AC_DEFUN([gl_FUNC_LINKAT],
             *)      gl_cv_func_linkat_slash="guessing no";;
           esac
          ])
-       rm -rf conftest.a conftest.b conftest.c conftest.d])
+       rm -rf conftest.a conftest.b conftest.c conftest.d conftest.e conftest.s])
     case "$gl_cv_func_linkat_slash" in
       *yes) gl_linkat_slash_bug=0 ;;
       *)    gl_linkat_slash_bug=1 ;;