From 7b29362d907d58e00a7a8033e1ef5faf4049740b Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 15 Aug 2023 12:35:13 +0200 Subject: [PATCH] Updating a shared session objects needs to do copy on write --- src/internal.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/internal.c b/src/internal.c index 0ff5e9d0d..443743a97 100644 --- a/src/internal.c +++ b/src/internal.c @@ -31810,6 +31810,15 @@ exit_scv: #ifdef HAVE_SESSION_TICKET int SetTicket(WOLFSSL* ssl, const byte* ticket, word32 length) { + /* If the session is shared, we need to copy-on-write */ + if (ssl->session->ref.count > 1) { + WOLFSSL_SESSION* nsession = wolfSSL_SESSION_dup(ssl->session); + if (nsession == NULL) + return MEMORY_E; + wolfSSL_FreeSession(ssl->ctx, ssl->session); + ssl->session = nsession; + } + /* Free old dynamic ticket if we already had one */ if (ssl->session->ticketLenAlloc > 0) { XFREE(ssl->session->ticket, ssl->heap, DYNAMIC_TYPE_SESSION_TICK);