Commit 9884dd613ede9946c512803c4caf438eb10e2d36

Carlos Martín Nieto 2016-08-05T18:40:37

SecureTransport: handle NULL trust on success The `SSLCopyPeerTrust` call can succeed but fail to return a trust object if it can't load the certificate chain and thus cannot check the validity of a certificate. This can lead to us calling `CFRelease` on a `NULL` trust object, causing a crash. Handle this by returning ECERTIFICATE.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/stransport_stream.c b/src/stransport_stream.c
index 66be58a..008bdfb 100644
--- a/src/stransport_stream.c
+++ b/src/stransport_stream.c
@@ -67,6 +67,9 @@ int stransport_connect(git_stream *stream)
 	if ((ret = SSLCopyPeerTrust(st->ctx, &trust)) != noErr)
 		goto on_error;
 
+	if (!trust)
+		return GIT_ECERTIFICATE;
+
 	if ((ret = SecTrustEvaluate(trust, &sec_res)) != noErr)
 		goto on_error;