]> Savannah Git Hosting - gnulib.git/commitdiff
symlinkat: Fix trailing slash handling.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Jan 2021 04:37:50 +0000 (05:37 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Jan 2021 04:56:38 +0000 (05:56 +0100)
* lib/symlinkat.c (rpl_symlinkat): Don't follow symlinks during the
trailing slash handling.
* modules/symlinkat (Depends-on): Update conditions.

ChangeLog
lib/symlinkat.c
modules/symlinkat

index bc2e552a1d3dfe7d8bd860b8c983420e4e7d1684..2663445a73022c282c66d519f080ffe126a48c59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-01-04  Bruno Haible  <bruno@clisp.org>
+
+       symlinkat: Fix trailing slash handling.
+       * lib/symlinkat.c (rpl_symlinkat): Don't follow symlinks during the
+       trailing slash handling.
+       * modules/symlinkat (Depends-on): Update conditions.
+
 2021-01-04  Bruno Haible  <bruno@clisp.org>
 
        mkfifoat: Update module description.
index 404fa653311d633fdaf3411ea2776c02d3dd5298..58ddb890564a6273d3080d8a2e395ae7784345c6 100644 (file)
@@ -27,6 +27,7 @@
 #if HAVE_SYMLINKAT
 # undef symlinkat
 
+#include <fcntl.h>
 #include <sys/stat.h>
 #include <string.h>
 
@@ -38,7 +39,8 @@ rpl_symlinkat (char const *contents, int fd, char const *name)
   if (len && name[len - 1] == '/')
     {
       struct stat st;
-      if (fstatat (fd, name, &st, 0) == 0 || errno == EOVERFLOW)
+      if (fstatat (fd, name, &st, AT_SYMLINK_NOFOLLOW) == 0
+          || errno == EOVERFLOW)
         errno = EEXIST;
       return -1;
     }
index 16d0fcc2bebeff304d435f12c0370c9e90b82a82..03b6a40f4634cfd7aac1b78f17a4641e721a8bc2 100644 (file)
@@ -9,10 +9,10 @@ m4/symlinkat.m4
 Depends-on:
 unistd
 extensions
+fcntl-h         [test $HAVE_SYMLINKAT = 0 || test $REPLACE_SYMLINKAT = 1]
 at-internal     [test $HAVE_SYMLINKAT = 0]
 errno           [test $HAVE_SYMLINKAT = 0]
 fchdir          [test $HAVE_SYMLINKAT = 0]
-fcntl-h         [test $HAVE_SYMLINKAT = 0]
 filename        [test $HAVE_SYMLINKAT = 0]
 openat-die      [test $HAVE_SYMLINKAT = 0]
 openat-h        [test $HAVE_SYMLINKAT = 0]