]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sectransp: fix EXC_BAD_ACCESS caused by uninitialized buffer
authorejanchivdorj <ejanchivdorj@tableau.com>
Tue, 25 May 2021 06:38:17 +0000 (23:38 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 25 May 2021 09:22:09 +0000 (11:22 +0200)
When the SecCertificateCopyCommonName function fails, it leaves
common_name in a invalid state so CFStringCompare uses the invalid
result, causing EXC_BAD_ACCESS.

The fix is to check the return value of the function before using the
name.

Closes #7126

lib/vtls/sectransp.c

index 4122384ddcdbc161b005e5eb6c9c6ff2cc15b6c0..edd375ea7d7349fc80c931213f5a06654fe2294c 100644 (file)
@@ -1158,12 +1158,14 @@ static OSStatus CopyIdentityWithLabel(char *label,
           (SecIdentityRef) CFArrayGetValueAtIndex(keys_list, i);
         err = SecIdentityCopyCertificate(identity, &cert);
         if(err == noErr) {
+          OSStatus copy_status = noErr;
 #if CURL_BUILD_IOS
           common_name = SecCertificateCopySubjectSummary(cert);
 #elif CURL_BUILD_MAC_10_7
-          SecCertificateCopyCommonName(cert, &common_name);
+          copy_status = SecCertificateCopyCommonName(cert, &common_name);
 #endif
-          if(CFStringCompare(common_name, label_cf, 0) == kCFCompareEqualTo) {
+          if(copy_status == noErr &&
+            CFStringCompare(common_name, label_cf, 0) == kCFCompareEqualTo) {
             CFRelease(cert);
             CFRelease(common_name);
             CFRetain(identity);