]> Savannah Git Hosting - gnulib.git/commitdiff
file-has-acl: remove __gl_acl_alloc member
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 7 Nov 2024 17:25:43 +0000 (09:25 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 7 Nov 2024 19:45:02 +0000 (11:45 -0800)
It may have been needed in earlier versions of this code,
but it is no longer needed.
* lib/acl.h (struct aclinfo): Remove __gl_acl_alloc.  All uses removed.
* lib/file-has-acl.c (get_aclinfo):
Use local, not the removed struct aclinfo slot.

ChangeLog
lib/acl.h
lib/file-has-acl.c

index 68a6ebd3a28cbf169721a005314af85f7b1d3a04..2bcee7d3f61a7997011cb66399bb628248243479 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-11-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       file-has-acl: remove __gl_acl_alloc member
+       It may have been needed in earlier versions of this code,
+       but it is no longer needed.
+       * lib/acl.h (struct aclinfo): Remove __gl_acl_alloc.  All uses removed.
+       * lib/file-has-acl.c (get_aclinfo):
+       Use local, not the removed struct aclinfo slot.
+
 2024-11-06  Paul Eggert  <eggert@cs.ucla.edu>
 
        opendirat: don’t depend on openat-safer
index 68a421a09354452417036929fec790bf05b65145..ca74fe6de8976057cf3f77d0a5ed3ffc9e62500d 100644 (file)
--- a/lib/acl.h
+++ b/lib/acl.h
@@ -49,11 +49,6 @@ struct aclinfo
      and u.err is the corresponding errno.  */
   ssize_t size;
 
-  /* The allocated size of buf.  This is sizeof u.__gl_acl_ch if the
-     buffer is not heap-allocated, and is larger otherwise.
-     For internal use only.  */
-  ssize_t __gl_acl_alloc;
-
   /* Security context string.  Do not modify its contents.  */
   char *scontext;
   /* Security context errno value.  It is zero if there was no
index 64291e02d48c8b0f53806762b9866809285c17f2..a436793388357190f2ebba79aefab12fe5e45042 100644 (file)
@@ -115,13 +115,13 @@ get_aclinfo (char const *name, struct aclinfo *ai, int flags)
 {
   int scontext_err = ENOTSUP;
   ai->buf = ai->u.__gl_acl_ch;
-  ai->__gl_acl_alloc = sizeof ai->u.__gl_acl_ch;
+  ssize_t acl_alloc = sizeof ai->u.__gl_acl_ch;
 
   ssize_t (*lsxattr) (char const *, char *, size_t)
     = (flags & ACL_SYMLINK_FOLLOW ? listxattr : llistxattr);
   while (true)
     {
-      ai->size = lsxattr (name, ai->buf, ai->__gl_acl_alloc);
+      ai->size = lsxattr (name, ai->buf, acl_alloc);
       if (0 < ai->size)
         break;
       ai->u.err = ai->size < 0 ? errno : 0;
@@ -140,32 +140,30 @@ get_aclinfo (char const *name, struct aclinfo *ai, int flags)
       /* Grow allocation to at least 'size'.  Grow it by a nontrivial
          amount, to defend against denial of service by an adversary
          that fiddles with ACLs.  */
-      ssize_t larger_alloc;
-      if (ckd_add (&larger_alloc, ai->__gl_acl_alloc, ai->__gl_acl_alloc >> 1))
-        {
-          ai->u.err = ENOMEM;
-          break;
-        }
       if (ai->buf != ai->u.__gl_acl_ch)
         {
           free (ai->buf);
           ai->buf = ai->u.__gl_acl_ch;
-          ai->__gl_acl_alloc = sizeof ai->u.__gl_acl_ch;
         }
-      ssize_t newalloc = MAX (size, larger_alloc);
-      if (SIZE_MAX < newalloc)
+      if (ckd_add (&acl_alloc, acl_alloc, acl_alloc >> 1))
+        {
+          ai->u.err = ENOMEM;
+          break;
+        }
+      if (acl_alloc < size)
+        acl_alloc = size;
+      if (SIZE_MAX < acl_alloc)
         {
           ai->u.err = ENOMEM;
           break;
         }
-      char *newbuf = malloc (newalloc);
+      char *newbuf = malloc (acl_alloc);
       if (!newbuf)
         {
           ai->u.err = errno;
           break;
         }
       ai->buf = newbuf;
-      ai->__gl_acl_alloc = newalloc;
     }
 
   if (0 < ai->size)