From e8f927db7da00d1671f871d3b2e89429aec3beb9 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Thu, 12 Nov 2020 15:33:09 +0200 Subject: [PATCH] ipasam: free trusted domain context on failure The context is hanging off a talloc memory context passed into the function so it will eventually be freed. It is better, though, to free it immediately when we exit from the fill_pdb_trusted_domain() function. Related: https://pagure.io/freeipa/issue/8576 Signed-off-by: Alexander Bokovoy Reviewed-By: Christian Heimes Reviewed-By: Rob Crittenden Reviewed-By: Christian Heimes Reviewed-By: Rob Crittenden --- daemons/ipa-sam/ipa_sam.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/daemons/ipa-sam/ipa_sam.c b/daemons/ipa-sam/ipa_sam.c index 46c28f6c7..c11e99177 100644 --- a/daemons/ipa-sam/ipa_sam.c +++ b/daemons/ipa-sam/ipa_sam.c @@ -2490,6 +2490,7 @@ static bool fill_pdb_trusted_domain(TALLOC_CTX *mem_ctx, LDAP_ATTRIBUTE_TRUST_DIRECTION, &td->trust_direction); if (!res) { + TALLOC_FREE(td); return false; } if (td->trust_direction == 0) { @@ -2501,6 +2502,7 @@ static bool fill_pdb_trusted_domain(TALLOC_CTX *mem_ctx, LDAP_ATTRIBUTE_TRUST_ATTRIBUTES, &td->trust_attributes); if (!res) { + TALLOC_FREE(td); return false; } if (td->trust_attributes == 0) { @@ -2512,6 +2514,7 @@ static bool fill_pdb_trusted_domain(TALLOC_CTX *mem_ctx, LDAP_ATTRIBUTE_TRUST_TYPE, &td->trust_type); if (!res) { + TALLOC_FREE(td); return false; } if (td->trust_type == 0) { @@ -2521,23 +2524,27 @@ static bool fill_pdb_trusted_domain(TALLOC_CTX *mem_ctx, td->trust_posix_offset = talloc_zero(td, uint32_t); if (td->trust_posix_offset == NULL) { + TALLOC_FREE(td); return false; } res = get_uint32_t_from_ldap_msg(ipasam_state, entry, LDAP_ATTRIBUTE_TRUST_POSIX_OFFSET, td->trust_posix_offset); if (!res) { + TALLOC_FREE(td); return false; } td->supported_enc_type = talloc_zero(td, uint32_t); if (td->supported_enc_type == NULL) { + TALLOC_FREE(td); return false; } res = get_uint32_t_from_ldap_msg(ipasam_state, entry, LDAP_ATTRIBUTE_SUPPORTED_ENC_TYPE, td->supported_enc_type); if (!res) { + TALLOC_FREE(td); return false; } if (*td->supported_enc_type == 0) {