Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 146a96d

Browse files
committed
openssl: don't try to teardown an unconnected SSL context
SSL_shutdown() does not like it when we pass an unitialized ssl context to it. This means that when we fail to connect to a host, we hide the error message saying so with OpenSSL's indecipherable error message.
1 parent 72b7c57 commit 146a96d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/openssl_stream.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
302302
typedef struct {
303303
git_stream parent;
304304
git_stream *io;
305+
bool connected;
305306
char *host;
306307
SSL *ssl;
307308
git_cert_x509 cert_info;
@@ -318,6 +319,8 @@ int openssl_connect(git_stream *stream)
318319
if ((ret = git_stream_connect(st->io)) < 0)
319320
return ret;
320321

322+
st->connected = true;
323+
321324
bio = BIO_new(&git_stream_bio_method);
322325
GITERR_CHECK_ALLOC(bio);
323326
bio->ptr = st->io;
@@ -406,9 +409,11 @@ int openssl_close(git_stream *stream)
406409
openssl_stream *st = (openssl_stream *) stream;
407410
int ret;
408411

409-
if ((ret = ssl_teardown(st->ssl)) < 0)
412+
if (st->connected && (ret = ssl_teardown(st->ssl)) < 0)
410413
return -1;
411414

415+
st->connected = false;
416+
412417
return git_stream_close(st->io);
413418
}
414419

0 commit comments

Comments
 (0)