mirror of
https://github.com/obgm/libcoap.git
synced 2026-10-30 14:35:48 +03:00
pki_sni_callback() kept the PKI SNI cache as one array of entries that hold the CA chain, certificate and key by value, and grew it with realloc() for each new SNI. The certificate and key of an entry are handed to the handshake with mbedtls_ssl_set_hs_ca_chain() and mbedtls_ssl_set_hs_own_cert(), so when a second client asked for a new SNI while another handshake was still running, that handshake was left using freed memory. Allocate each entry on its own and keep an array of pointers to them, so an entry stays where it is for the life of the context. Also free the partly set up credentials when setting up a new entry fails. Add a unit test.