]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sectransp: prevent CFRelease() of NULL
authorDaniel Stenberg <daniel@haxx.se>
Mon, 31 Jul 2023 09:01:51 +0000 (11:01 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 1 Aug 2023 06:17:26 +0000 (08:17 +0200)
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

index 348bbe202a1e012868374f049d9974950c15fa39..0459ac06559c874f0c8a1e37ab3bfce6957d5da7 100644 (file)
@@ -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);
       }