mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-04-10 04:38:23 +02:00
Check *_get_ex_data() and *_set_ex_data() return values.
Closes #3389. Thanks to Qingpeng Du.
This commit is contained in:
parent
2c4967a2a4
commit
0e04dfc032
|
|
@ -1361,7 +1361,10 @@ static int client_tls_opts_set(struct mosquitto *mosq, struct mosq_config *cfg)
|
|||
err_printf(cfg, "Error: Unable to create SSL_CTX.\n");
|
||||
return 1;
|
||||
}
|
||||
SSL_CTX_set_ex_data(cfg->ssl_ctx, tls_ex_index_cfg, cfg);
|
||||
if(!SSL_CTX_set_ex_data(cfg->ssl_ctx, tls_ex_index_cfg, cfg)){
|
||||
err_printf(cfg, "Error: Unable to set SSL_CTX ex data.\n");
|
||||
return 1;
|
||||
}
|
||||
mosquitto_void_option(mosq, MOSQ_OPT_SSL_CTX, cfg->ssl_ctx);
|
||||
mosquitto_int_option(mosq, MOSQ_OPT_SSL_CTX_WITH_DEFAULTS, 1);
|
||||
SSL_CTX_set_keylog_callback(cfg->ssl_ctx, tls_keylog_callback);
|
||||
|
|
|
|||
|
|
@ -689,6 +689,8 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
|
|||
uint8_t tls_alpn_wire[256];
|
||||
uint8_t tls_alpn_len;
|
||||
|
||||
net__init_tls();
|
||||
|
||||
#ifndef WITH_BROKER
|
||||
if(mosq->user_ssl_ctx){
|
||||
mosq->ssl_ctx = mosq->user_ssl_ctx;
|
||||
|
|
@ -705,7 +707,6 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
|
|||
* has not been set, or if both of MOSQ_OPT_SSL_CTX and
|
||||
* MOSQ_OPT_SSL_CTX_WITH_DEFAULTS are set. */
|
||||
if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk || mosq->tls_use_os_certs){
|
||||
net__init_tls();
|
||||
if(!mosq->ssl_ctx){
|
||||
|
||||
mosq->ssl_ctx = SSL_CTX_new(TLS_client_method());
|
||||
|
|
@ -922,7 +923,11 @@ int net__socket_connect_step3(struct mosquitto *mosq, const char *host)
|
|||
return MOSQ_ERR_TLS;
|
||||
}
|
||||
|
||||
SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq);
|
||||
if(!SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq)){
|
||||
net__socket_close(mosq);
|
||||
net__print_ssl_error(mosq, "while setting SSL ex data");
|
||||
return MOSQ_ERR_TLS;
|
||||
}
|
||||
bio = BIO_new_socket(mosq->sock, BIO_NOCLOSE);
|
||||
if(!bio){
|
||||
net__socket_close(mosq);
|
||||
|
|
|
|||
|
|
@ -250,8 +250,11 @@ struct mosquitto *net__socket_accept(struct mosquitto__listener_sock *listensock
|
|||
context__cleanup(new_context, true);
|
||||
return NULL;
|
||||
}
|
||||
SSL_set_ex_data(new_context->ssl, tls_ex_index_context, new_context);
|
||||
SSL_set_ex_data(new_context->ssl, tls_ex_index_listener, new_context->listener);
|
||||
if(!SSL_set_ex_data(new_context->ssl, tls_ex_index_context, new_context)
|
||||
|| !SSL_set_ex_data(new_context->ssl, tls_ex_index_listener, new_context->listener)){
|
||||
context__cleanup(new_context, true);
|
||||
return NULL;
|
||||
}
|
||||
new_context->want_write = true;
|
||||
bio = BIO_new_socket(new_sock, BIO_NOCLOSE);
|
||||
SSL_set_bio(new_context->ssl, bio, bio);
|
||||
|
|
|
|||
Loading…
Reference in a new issue