From: Neil Horman Date: Thu, 16 Jan 2025 18:12:15 +0000 (-0500) Subject: Enhance get_peer_token to not require memcpy X-Git-Tag: openssl-3.5.0-alpha1~236 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a2fe6435cac29b7d74595667bddfa11b4e0cba72;p=thirdparty%2Fopenssl.git Enhance get_peer_token to not require memcpy Instead of copying the token thats store, return a pointer to it along with a pointer to the token struct to free should we need to Reviewed-by: Matt Caswell Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/26517) --- diff --git a/include/internal/quic_ssl.h b/include/internal/quic_ssl.h index e95af55de90..f860b1b3a7a 100644 --- a/include/internal/quic_ssl.h +++ b/include/internal/quic_ssl.h @@ -32,7 +32,8 @@ int ossl_quic_set_token_store(SSL_CTX *ctx, SSL_TOKEN_STORE_HANDLE *hdl); int ossl_quic_update_peer_token(SSL_CTX *ctx, BIO_ADDR *peer, const uint8_t *token, size_t token_len); int ossl_quic_get_peer_token(SSL_CTX *ctx, BIO_ADDR *peer, - uint8_t **token, size_t *token_len); + uint8_t **token, size_t *token_len, + void **token_free_ptr); __owur int ossl_quic_init(SSL *s); void ossl_quic_deinit(SSL *s); diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 0ba040d6f35..1afa4f27a8e 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -4846,7 +4846,8 @@ int ossl_quic_update_peer_token(SSL_CTX *ctx, BIO_ADDR *peer, } int ossl_quic_get_peer_token(SSL_CTX *ctx, BIO_ADDR *peer, - uint8_t **token, size_t *token_len) + uint8_t **token, size_t *token_len, + void **token_free_ptr) { SSL_TOKEN_STORE *c = ctx->tokencache; QUIC_TOKEN *key = NULL; @@ -4865,15 +4866,15 @@ int ossl_quic_get_peer_token(SSL_CTX *ctx, BIO_ADDR *peer, tok = NULL; goto out; } - memcpy(*token, tok->token, tok->token_len); + *token = tok->token; *token_len = tok->token_len; + *token_free_ptr = tok; lh_QUIC_TOKEN_delete(c->cache, key); rc = 1; } out: ossl_crypto_mutex_unlock(c->mutex); - free_quic_token(tok); free_quic_token(key); return rc; }