From a44d8b6c280e55873aadc88354a353abc8eac188 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Nov 2024 09:25:43 -0800 Subject: [PATCH] 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. --- ChangeLog | 9 +++++++++ lib/acl.h | 5 ----- lib/file-has-acl.c | 24 +++++++++++------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68a6ebd3a2..2bcee7d3f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-11-07 Paul Eggert + + 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 opendirat: don’t depend on openat-safer diff --git a/lib/acl.h b/lib/acl.h index 68a421a093..ca74fe6de8 100644 --- 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 diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c index 64291e02d4..a436793388 100644 --- a/lib/file-has-acl.c +++ b/lib/file-has-acl.c @@ -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) -- 2.39.5