]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Enhance get_peer_token to not require memcpy
authorNeil Horman <nhorman@openssl.org>
Thu, 16 Jan 2025 18:12:15 +0000 (13:12 -0500)
committerNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 16:27:33 +0000 (11:27 -0500)
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 <matt@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26517)

include/internal/quic_ssl.h
ssl/quic/quic_impl.c

index e95af55de90c2bd33c863095bda23fce1af2236f..f860b1b3a7aa5cafff5d251fde00287fb1e24a20 100644 (file)
@@ -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);
index 0ba040d6f3565ccdb59e866e8de23ba6b81fabe3..1afa4f27a8e21eb259bb21a628219981e0370943 100644 (file)
@@ -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;
 }