]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Centralize freeing of tokens
authorNeil Horman <nhorman@openssl.org>
Mon, 27 Jan 2025 18:04:08 +0000 (13:04 -0500)
committerNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 16:27:33 +0000 (11:27 -0500)
This will make it easier to refcount them in a moment

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_channel.c
ssl/quic/quic_impl.c

index f860b1b3a7aa5cafff5d251fde00287fb1e24a20..7c1bdf50cf02b776732ab792f4e2b522467fd0c9 100644 (file)
@@ -25,6 +25,7 @@ __owur SSL *ossl_quic_new_listener_from(SSL *ssl, uint64_t flags);
 __owur SSL *ossl_quic_new_from_listener(SSL *ssl, uint64_t flags);
 __owur SSL *ossl_quic_new_domain(SSL_CTX *ctx, uint64_t flags);
 
+typedef void* QTOK;
 SSL_TOKEN_STORE_HANDLE *ossl_quic_new_token_store(void);
 void ossl_quic_free_token_store(SSL_TOKEN_STORE_HANDLE *hdl);
 SSL_TOKEN_STORE_HANDLE *ossl_quic_get_token_store(SSL_CTX *ctx);
@@ -33,7 +34,8 @@ 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,
-                             void **token_free_ptr);
+                             QTOK **token_free_ptr);
+void ossl_quic_free_peer_token(QTOK *token);
 
 __owur int ossl_quic_init(SSL *s);
 void ossl_quic_deinit(SSL *s);
index bfefa272c34755b9101a9ee4a26f11a278df624c..7e271bd5b33881318489a23a8ec52d6e40bf4d64 100644 (file)
@@ -2799,7 +2799,7 @@ int ossl_quic_channel_start(QUIC_CHANNEL *ch)
 {
     uint8_t *token;
     size_t token_len;
-    void *token_ptr;
+    QTOK *token_ptr;
 
     if (ch->is_server)
         /*
@@ -2824,9 +2824,10 @@ int ossl_quic_channel_start(QUIC_CHANNEL *ch)
                                                    &token, &token_len,
                                                    &token_ptr)) {
         if (!ossl_quic_tx_packetiser_set_initial_token(ch->txp, token,
-                                                       token_len, free_token,
+                                                       token_len,
+                                                       free_peer_token,
                                                        token_ptr))
-            free_token(NULL, 0, token_ptr);
+            free_peer_token(NULL, 0, token_ptr);
     }
     /* Plug in secrets for the Initial EL. */
     if (!ossl_quic_provide_initial_secret(ch->port->engine->libctx,
index 4f99a68934b1ebcf750574b8be1de574e77a3a14..09f103c6af0f144933fcf3184e96d4fe28cb2444 100644 (file)
@@ -4847,7 +4847,7 @@ 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,
-                             void **token_free_ptr)
+                             QTOK **token_free_ptr)
 {
     SSL_TOKEN_STORE *c = ctx->tokencache;
     QUIC_TOKEN *key = NULL;
@@ -4863,7 +4863,7 @@ int ossl_quic_get_peer_token(SSL_CTX *ctx, BIO_ADDR *peer,
     if (tok != NULL) {
         *token = tok->token;
         *token_len = tok->token_len;
-        *token_free_ptr = tok;
+        *token_free_ptr = (QTOK *)tok;
         lh_QUIC_TOKEN_delete(c->cache, key);
         rc = 1;
     }
@@ -4873,6 +4873,11 @@ int ossl_quic_get_peer_token(SSL_CTX *ctx, BIO_ADDR *peer,
     return rc;
 }
 
+void ossl_quic_free_peer_token(QTOK *token)
+{
+    OPENSSL_free(token);
+}
+
 /*
  * SSL_get_accept_connection_queue_len
  * -----------------------------------