Skip to content

Commit d497d80

Browse files
FiloSottiledmitshur
authored andcommitted
[release-branch.go1.11] 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 #32281 Updates #28092 Updates #30763 Change-Id: I5ee7ca276b753a48abc3aedfb78b8af68b448dd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/178537 Reviewed-by: Adam Langley <agl@golang.org> (cherry picked from commit a3d4655) Reviewed-on: https://go-review.googlesource.com/c/go/+/179340 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
1 parent efa061d commit d497d80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/crypto/x509/root_cgo_darwin.go

+4-4
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)