Skip to content

Commit

Permalink
Fix cherry picked commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Nov 18, 2020
1 parent b81f0d6 commit 4e3b8ed
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,24 +855,14 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
#endif


void net__socket_close_compat(struct mosquitto *mosq)
{
#ifdef WITH_BROKER
struct mosquitto_db *db = mosquitto__get_db();
net__socket_close(db, mosq);
#else
net__socket_close(mosq);
#endif
}

int net__socket_connect_step3(struct mosquitto *mosq, const char *host)
{
#ifdef WITH_TLS
BIO *bio;

int rc = net__init_ssl_ctx(mosq);
if(rc){
net__socket_close_compat(mosq);
net__socket_close(mosq);
return rc;
}

Expand All @@ -882,15 +872,15 @@ int net__socket_connect_step3(struct mosquitto *mosq, const char *host)
}
mosq->ssl = SSL_new(mosq->ssl_ctx);
if(!mosq->ssl){
net__socket_close_compat(mosq);
net__socket_close(mosq);
net__print_ssl_error(mosq);
return MOSQ_ERR_TLS;
}

SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq);
bio = BIO_new_socket(mosq->sock, BIO_NOCLOSE);
if(!bio){
net__socket_close_compat(mosq);
net__socket_close(mosq);
net__print_ssl_error(mosq);
return MOSQ_ERR_TLS;
}
Expand All @@ -900,12 +890,12 @@ int net__socket_connect_step3(struct mosquitto *mosq, const char *host)
* required for the SNI resolving
*/
if(SSL_set_tlsext_host_name(mosq->ssl, host) != 1) {
net__socket_close_compat(mosq);
net__socket_close(mosq);
return MOSQ_ERR_TLS;
}

if(net__socket_connect_tls(mosq)){
net__socket_close_compat(mosq);
net__socket_close(mosq);
return MOSQ_ERR_TLS;
}

Expand Down

0 comments on commit 4e3b8ed

Please sign in to comment.