wolfssl: proof use of wolfSSL_i2d_SSL_SESSION

While wolfSSL_i2d_SSL_SESSION() does not change the passed pointer, like
OpenSSL does, it may one day decide to do so. Pass a copy instead to be
future-proof to such a change in wolfSSL's implementation.

Closes #20008
This commit is contained in:
Stefan Eissing 2025-12-17 11:20:42 +01:00 committed by Daniel Stenberg
parent de8470c6e5
commit be3c226bb0
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -425,7 +425,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf,
{
CURLcode result = CURLE_OK;
struct Curl_ssl_session *sc_session = NULL;
unsigned char *sdata = NULL, *qtp_clone = NULL;
unsigned char *sdata = NULL, *sdata_ptr, *qtp_clone = NULL;
unsigned int sdata_len;
unsigned int earlydata_max = 0;
@ -438,13 +438,15 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf,
result = CURLE_FAILED_INIT;
goto out;
}
sdata = curlx_calloc(1, sdata_len);
sdata = sdata_ptr = curlx_calloc(1, sdata_len);
if(!sdata) {
failf(data, "unable to allocate session buffer of %u bytes", sdata_len);
result = CURLE_OUT_OF_MEMORY;
goto out;
}
sdata_len = wolfSSL_i2d_SSL_SESSION(session, &sdata);
/* wolfSSL right now does not change the last parameter here, but it
* might one day decide to do so for OpenSSL compatibility. */
sdata_len = wolfSSL_i2d_SSL_SESSION(session, &sdata_ptr);
if(sdata_len <= 0) {
CURL_TRC_CF(data, cf, "fail to serialize session: %u", sdata_len);
result = CURLE_FAILED_INIT;