Commit 3b05c3c2 authored by Filippo Valsorda's avatar Filippo Valsorda Committed by Dmitri Shuralyov

[release-branch.go1.12] 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 #32282
Updates #28092
Updates #30763

Change-Id: I5ee7ca276b753a48abc3aedfb78b8af68b448dd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/178537Reviewed-by: default avatarAdam Langley <agl@golang.org>
(cherry picked from commit a3d4655c)
Reviewed-on: https://go-review.googlesource.com/c/go/+/179339
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDmitri Shuralyov <dmitshur@golang.org>
parent afcfe0d3
...@@ -16,7 +16,7 @@ package x509 ...@@ -16,7 +16,7 @@ package x509
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h> #include <Security/Security.h>
static bool isSSLPolicy(SecPolicyRef policyRef) { static Boolean isSSLPolicy(SecPolicyRef policyRef) {
if (!policyRef) { if (!policyRef) {
return false; return false;
} }
...@@ -24,13 +24,13 @@ static bool isSSLPolicy(SecPolicyRef policyRef) { ...@@ -24,13 +24,13 @@ static bool isSSLPolicy(SecPolicyRef policyRef) {
if (properties == NULL) { if (properties == NULL) {
return false; return false;
} }
Boolean isSSL = false;
CFTypeRef value = NULL; CFTypeRef value = NULL;
if (CFDictionaryGetValueIfPresent(properties, kSecPolicyOid, (const void **)&value)) { if (CFDictionaryGetValueIfPresent(properties, kSecPolicyOid, (const void **)&value)) {
CFRelease(properties); isSSL = CFEqual(value, kSecPolicyAppleSSL);
return CFEqual(value, kSecPolicyAppleSSL);
} }
CFRelease(properties); CFRelease(properties);
return false; return isSSL;
} }
// sslTrustSettingsResult obtains the final kSecTrustSettingsResult value // sslTrustSettingsResult obtains the final kSecTrustSettingsResult value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment