From 0b947e8ca2c23146375ba61281e530c843a47fcb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 31 Jul 2023 11:01:51 +0200 Subject: [PATCH] sectransp: prevent CFRelease() of NULL When SecCertificateCopyCommonName() returns NULL, the common_name pointer remains set to NULL which apparently when calling CFRelease() on (sometimes?) crashes. Reported-by: Guillaume Algis Fixes #9194 Closes #11554 --- lib/vtls/sectransp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c index 348bbe202a..0459ac0655 100644 --- a/lib/vtls/sectransp.c +++ b/lib/vtls/sectransp.c @@ -1086,7 +1086,6 @@ static OSStatus CopyIdentityWithLabel(char *label, CFArrayRef keys_list; CFIndex keys_list_count; CFIndex i; - CFStringRef common_name; /* SecItemCopyMatching() was introduced in iOS and Snow Leopard. kSecClassIdentity was introduced in Lion. If both exist, let's use them @@ -1134,6 +1133,7 @@ static OSStatus CopyIdentityWithLabel(char *label, (SecIdentityRef) CFArrayGetValueAtIndex(keys_list, i); err = SecIdentityCopyCertificate(identity, &cert); if(err == noErr) { + CFStringRef common_name = NULL; OSStatus copy_status = noErr; #if CURL_BUILD_IOS common_name = SecCertificateCopySubjectSummary(cert); @@ -1149,7 +1149,8 @@ static OSStatus CopyIdentityWithLabel(char *label, status = noErr; break; } - CFRelease(common_name); + if(common_name) + CFRelease(common_name); } CFRelease(cert); }