Some static checking helped find an off-by-one bug that I introduced to your Gnulib patch. The bug caused file_has_acl to sometimes incorrectly return -1 when given a nontrivial ACL in which a WHOLEN is a multiple of 4. Sorry about that. I installed the attached further patch to fix it.
From d65e5a8ba77595a598c9ddb8dfa09c4aea732659 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 27 Dec 2022 20:00:58 -0800
Subject: [PATCH] file-has-acl: fix recently-introduced NFSv4 bug

* lib/file-has-acl.c (acl_nfs4_nontrivial): Fix off-by-one
error when rounding WHOLEN up to next multiple of 4.
Pacify GCC 12.2.1 -Wcast-align.
---
 ChangeLog          | 5 +++++
 lib/file-has-acl.c | 9 +++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 12c14a2e7a..be0fb22078 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2022-12-27  Paul Eggert  <egg...@cs.ucla.edu>
 
+	file-has-acl: fix recently-introduced NFSv4 bug
+	* lib/file-has-acl.c (acl_nfs4_nontrivial): Fix off-by-one
+	error when rounding WHOLEN up to next multiple of 4.
+	Pacify GCC 12.2.1 -Wcast-align.
+
 	Add --pull, --gen options to build-aux/bootstrap
 	This supports a single bootstrap script with --pull and --gen
 	options, as an alternative to separate autogen.sh and autopull.sh
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 676523ba82..7876edc4f0 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -81,9 +81,10 @@ acl_nfs4_nontrivial (uint32_t *xattr, ssize_t nbytes)
       uint32_t flag = ntohl (xattr[1]);
       uint32_t wholen = ntohl (xattr[3]);
       xattr += 4;
-      int64_t wholen4 = wholen;
-      wholen4 = ((wholen4 + (BYTES_PER_NETWORK_UINT))
-                 & ~ (BYTES_PER_NETWORK_UINT - 1));
+      int whowords = (wholen / BYTES_PER_NETWORK_UINT
+                      + (wholen % BYTES_PER_NETWORK_UINT != 0));
+      int64_t wholen4 = whowords;
+      wholen4 *= BYTES_PER_NETWORK_UINT;
 
       /* Trivial ACLs have only ACE4_ACCESS_ALLOWED_ACE_TYPE or
          ACE4_ACCESS_DENIED_ACE_TYPE.  */
@@ -115,7 +116,7 @@ acl_nfs4_nontrivial (uint32_t *xattr, ssize_t nbytes)
         return 1;
       ace_found |= ace_found_bit;
 
-      xattr = (uint32_t *) ((char *) xattr + wholen4);
+      xattr += whowords;
     }
 
   return 0;
-- 
2.25.1

Reply via email to