From 3d1894d8dd3f33aeda81d674c2a1f19fded60085 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 5 Jan 2021 05:37:50 +0100 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ lib/symlinkat.c | 4 +++- modules/symlinkat | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc2e552a1d..2663445a73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-01-04 Bruno Haible + + 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 mkfifoat: Update module description. diff --git a/lib/symlinkat.c b/lib/symlinkat.c index 404fa65331..58ddb89056 100644 --- a/lib/symlinkat.c +++ b/lib/symlinkat.c @@ -27,6 +27,7 @@ #if HAVE_SYMLINKAT # undef symlinkat +#include #include #include @@ -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; } diff --git a/modules/symlinkat b/modules/symlinkat index 16d0fcc2be..03b6a40f46 100644 --- a/modules/symlinkat +++ b/modules/symlinkat @@ -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] -- 2.39.5