On 2026-06-16 11:50, Bruno Haible wrote:
Paul Eggert wrote:
int
fchmodat (int dir, char const *file, mode_t mode, int flags)
{
+ if (file && *file)
+ flags &= ~AT_EMPTY_PATH;
+ else if (! (flags & AT_EMPTY_PATH))
+ {
+ errno = ENOENT;
+ return -1;
+ }
+ else if (! (flags & AT_SYMLINK_NOFOLLOW))
+ return fchmod (dir, mode);
Shouldn't the last line read
return fchmod (dir == AT_FDCWD ? "." : dir, mode);
Thanks, good catch, though the fix isn't quite right. First, fchmod
needs an int not a string. Second, 'return dir == AT_FDCWD ? chmod (".",
mode) : fchmod (dir, mode);' wouldn't be quite right either, as the
chmod would wrongly fail when the working directory is not searchable.
fchmodat (AT_FDCWD, "", 0700, AT_EMPTY_PATH) is supposed to succeed if
you own the working directory, even if you can't search it.
I installed the attached patch to fix this. Although this still doesn't
add AT_EMPTY_PATH support to platforms that lack it, the goal is merely
to not break AT_EMPTY_PATH on platforms that do have it.From 797d7a623225971b8a4d7634540e9086e94f5bb5 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 18 Jun 2026 09:29:15 -0700
Subject: [PATCH] fchmodat: fix AT_FDCWD + AT_EMPTY_PATH
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lib/fchmodat.c (fchmodat): When following symlinks and with
AT_FDCWD and an empty filename, don’t use fchmod as it will fail.
Instead, fall back on the usual orig_fchmodat call, as this does
the right thing if AT_EMPTY_PATH support is present there.
Using chmod (".", ...) wouldn’t be quite right here, as it would
go awry if the working directory is not searchable.
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-06/msg00068.html
---
ChangeLog | 12 ++++++++++++
lib/fchmodat.c | 2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 5b7399ed1b..cc4ca63526 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-06-18 Paul Eggert <[email protected]>
+
+ fchmodat: fix AT_FDCWD + AT_EMPTY_PATH
+ * lib/fchmodat.c (fchmodat): When following symlinks and with
+ AT_FDCWD and an empty filename, don’t use fchmod as it will fail.
+ Instead, fall back on the usual orig_fchmodat call, as this does
+ the right thing if AT_EMPTY_PATH support is present there.
+ Using chmod (".", ...) wouldn’t be quite right here, as it would
+ go awry if the working directory is not searchable.
+ Problem reported by Bruno Haible in:
+ https://lists.gnu.org/r/bug-gnulib/2026-06/msg00068.html
+
2026-06-18 Bruno Haible <[email protected]>
stdbit-h: Work around syntax error in FreeBSD 15.1 <stdbit.h>.
diff --git a/lib/fchmodat.c b/lib/fchmodat.c
index c41768935b..fa22590153 100644
--- a/lib/fchmodat.c
+++ b/lib/fchmodat.c
@@ -71,7 +71,7 @@ fchmodat (int dir, char const *file, mode_t mode, int flags)
errno = ENOENT;
return -1;
}
- else if (! (flags & AT_SYMLINK_NOFOLLOW))
+ else if (! (flags & AT_SYMLINK_NOFOLLOW) && 0 <= dir)
return fchmod (dir, mode);
# if HAVE_NEARLY_WORKING_FCHMODAT
--
2.53.0