From cb9f9f4c04e8c8b2b9806de33d5d87ec6a0fa585 Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 24 Nov 2022 22:05:38 -0500 Subject: [PATCH] sock/posix: free the allocated memory Related reference: OPENSSL_hexstr2buf() does the same thing as OPENSSL_hexstr2buf_ex(), but allocates the space for the result, and returns the result. It uses a default separator of ':'. The memory is allocated by calling OPENSSL_malloc() and should be released by calling OPENSSL_free(). Change-Id: I0d2b9b66a41e53f8b438470e59a478c17df2e1e6 Signed-off-by: GangCao Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15647 Tested-by: SPDK CI Jenkins Reviewed-by: wanghailiang Reviewed-by: Changpeng Liu Reviewed-by: Aleksey Marchuk Community-CI: Mellanox Build Bot --- module/sock/posix/posix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index 220c41d95..1bb482f38 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -546,10 +546,12 @@ posix_sock_tls_psk_server_cb(SSL *ssl, } if (key_len > max_psk_len) { SPDK_ERRLOG("Insufficient buffer size to copy PSK\n"); + OPENSSL_free(default_psk); goto err; } memcpy(psk, default_psk, key_len); + OPENSSL_free(default_psk); return key_len; @@ -585,6 +587,7 @@ posix_sock_tls_psk_client_cb(SSL *ssl, const char *hint, } if ((strlen(impl_opts->psk_identity) + 1 > max_identity_len) || (key_len > max_psk_len)) { + OPENSSL_free(default_psk); SPDK_ERRLOG("PSK ID or Key buffer is not sufficient\n"); goto err; } @@ -593,6 +596,7 @@ posix_sock_tls_psk_client_cb(SSL *ssl, const char *hint, memcpy(psk, default_psk, key_len); SPDK_DEBUGLOG(sock_posix, "Provided out-of-band (OOB) PSK for TLS1.3 client\n"); + OPENSSL_free(default_psk); return key_len;