Skip to content

Commit a3d4655

Browse files
committed
crypto/x509: fix value ownership in isSSLPolicy on macOS
CFDictionaryGetValueIfPresent does not take ownership of the value, so releasing the properties dictionary before passing the value to CFEqual can crash. Not really clear why this works most of the time. See https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html Fixes #28092 Hopefully fixes #30763 Change-Id: I5ee7ca276b753a48abc3aedfb78b8af68b448dd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/178537 Reviewed-by: Adam Langley <[email protected]>
1 parent 06b0bab commit a3d4655

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/crypto/x509/root_cgo_darwin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ package x509
1616
#include <CoreFoundation/CoreFoundation.h>
1717
#include <Security/Security.h>
1818
19-
static bool isSSLPolicy(SecPolicyRef policyRef) {
19+
static Boolean isSSLPolicy(SecPolicyRef policyRef) {
2020
if (!policyRef) {
2121
return false;
2222
}
2323
CFDictionaryRef properties = SecPolicyCopyProperties(policyRef);
2424
if (properties == NULL) {
2525
return false;
2626
}
27+
Boolean isSSL = false;
2728
CFTypeRef value = NULL;
2829
if (CFDictionaryGetValueIfPresent(properties, kSecPolicyOid, (const void **)&value)) {
29-
CFRelease(properties);
30-
return CFEqual(value, kSecPolicyAppleSSL);
30+
isSSL = CFEqual(value, kSecPolicyAppleSSL);
3131
}
3232
CFRelease(properties);
33-
return false;
33+
return isSSL;
3434
}
3535
3636
// sslTrustSettingsResult obtains the final kSecTrustSettingsResult value

0 commit comments

Comments
 (0)