From: Volker Lendecke Date: Thu, 14 Jan 2021 20:52:51 +0000 (+0100) Subject: sharesec: Simplify add_ace() X-Git-Tag: tevent-0.11.0~2002 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=791b477ca5ef8fdbdc7b144ad5d3c679644394a0;p=thirdparty%2Fsamba.git sharesec: Simplify add_ace() Use ADD_TO_ARRAY Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/utils/sharesec.c b/source3/utils/sharesec.c index 97ff0cfc9c5..19841cc5a13 100644 --- a/source3/utils/sharesec.c +++ b/source3/utils/sharesec.c @@ -90,21 +90,21 @@ static struct security_descriptor* parse_acl_string(TALLOC_CTX *mem_ctx, const c /* add an ACE to a list of ACEs in a struct security_acl */ static bool add_ace(TALLOC_CTX *mem_ctx, struct security_acl **the_acl, struct security_ace *ace) { - struct security_acl *new_ace; - struct security_ace *aces; - if (! *the_acl) { - return (((*the_acl) = make_sec_acl(mem_ctx, 3, 1, ace)) != NULL); + struct security_acl *acl = *the_acl; + + if (acl == NULL) { + acl = make_sec_acl(mem_ctx, 3, 1, ace); + if (acl == NULL) { + return false; + } } - if (!(aces = SMB_CALLOC_ARRAY(struct security_ace, 1+(*the_acl)->num_aces))) { - return False; + if (acl->num_aces == UINT32_MAX) { + return false; } - memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct - security_ace)); - memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace)); - new_ace = make_sec_acl(mem_ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); - SAFE_FREE(aces); - (*the_acl) = new_ace; + ADD_TO_ARRAY( + acl, struct security_ace, *ace, &acl->aces, &acl->num_aces); + *the_acl = acl; return True; }