]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: fix aclinfo cache bug
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 7 Nov 2024 20:32:21 +0000 (12:32 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Nov 2024 07:41:18 +0000 (23:41 -0800)
Found when testing on a new platform with a new file system.
* src/ls.c (file_has_aclinfo_cache): For failures, also cache
return value, scontext, and scontext_err, and when using cached
values make sure buf and size have reasonable values for
aclinfo_free etc.

src/ls.c

index 962737432d951e176e176e8eb36c9efb0f30c2f3..dd61fbe620444d5253f73cc57cf9b4a370d37b5d 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3284,19 +3284,33 @@ static int
 file_has_aclinfo_cache (char const *file, struct fileinfo *f,
                         struct aclinfo *ai, int flags)
 {
-  /* st_dev of the most recently processed device for which we've
-     found that file_has_acl fails indicating lack of support.  */
+  /* st_dev and associated info for the most recently processed device
+     for which file_has_acl failed indicating lack of support.  */
+  static int unsupported_return;
+  static char *unsupported_scontext;
+  static int unsupported_scontext_err;
   static dev_t unsupported_device;
 
   if (f->stat.st_dev == unsupported_device)
     {
+      ai->buf = ai->u.__gl_acl_ch;
+      ai->size = 0;
+      ai->scontext = unsupported_scontext;
+      ai->scontext_err = unsupported_scontext_err;
       errno = ENOTSUP;
-      return 0;
+      return unsupported_return;
     }
 
+  errno = 0;
   int n = file_has_aclinfo (file, ai, flags);
-  if (n <= 0 && !acl_errno_valid (ai->u.err))
-    unsupported_device = f->stat.st_dev;
+  int err = errno;
+  if (n <= 0 && !acl_errno_valid (err))
+    {
+      unsupported_return = n;
+      unsupported_scontext = ai->scontext;
+      unsupported_scontext_err = ai->scontext_err;
+      unsupported_device = f->stat.st_dev;
+    }
   return n;
 }