Commit 03994912795f1a6d2bd560e0bce5af64b9c0dee2

Etienne Samson 2018-08-29T01:57:24

openssl: only say we're connected if the connection succeeded ssl_close uses this boolean to know if SSL_shutdown should be called. It turns out OpenSSL auto-shutdowns on failure, so if the call to SSL_connect fails, it will complain about "shutdown while in init", trampling the original error.

diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index 4b29d98..a68f9a9 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -586,8 +586,6 @@ int openssl_connect(git_stream *stream)
 	if ((ret = git_stream_connect(st->io)) < 0)
 		return ret;
 
-	st->connected = true;
-
 	bio = BIO_new(git_stream_bio_method);
 	GITERR_CHECK_ALLOC(bio);
 
@@ -602,6 +600,8 @@ int openssl_connect(git_stream *stream)
 	if ((ret = SSL_connect(st->ssl)) <= 0)
 		return ssl_set_error(st->ssl, ret);
 
+	st->connected = true;
+
 	return verify_server_cert(st->ssl, st->host);
 }