net: sockets: tls: Fix crashes in get DTLS CID socket options

Get TLS_DTLS_CID_STATUS and TLS_DTLS_PEER_CID_VALUE utilize
mbedtls_ssl_get_peer_cid, which expects that mbedtls_ssl_setup
has been done.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
This commit is contained in:
Markus Lassila 2024-01-18 15:58:24 +02:00 committed by Henrik Brix Andersen
parent b6e48d04f6
commit 681330aaf0

View file

@ -1769,6 +1769,10 @@ static int tls_opt_dtls_peer_connection_id_value_get(struct tls_context *context
int enabled = false;
int ret;
if (!context->is_initialized) {
return -ENOTCONN;
}
ret = mbedtls_ssl_get_peer_cid(&context->ssl, &enabled, optval, optlen);
if (!enabled) {
*optlen = 0;
@ -1794,6 +1798,10 @@ static int tls_opt_dtls_connection_id_status_get(struct tls_context *context,
return -EINVAL;
}
if (!context->is_initialized) {
return -ENOTCONN;
}
ret = mbedtls_ssl_get_peer_cid(&context->ssl, &enabled,
cid.cid,
&cid.cid_len);