Skip to content

Commit cba9ffd

Browse files
authored
Merge pull request #9782 from kareem-wolfssl/zd21204
Ensure length is at least ID_LEN in SetTicket.
2 parents a4e2d85 + aaf6aa5 commit cba9ffd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/internal.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34817,6 +34817,8 @@ int SendCertificateVerify(WOLFSSL* ssl)
3481734817
#ifdef HAVE_SESSION_TICKET
3481834818
int SetTicket(WOLFSSL* ssl, const byte* ticket, word32 length)
3481934819
{
34820+
word32 sessIdLen = ID_LEN;
34821+
3482034822
if (!HaveUniqueSessionObj(ssl))
3482134823
return MEMORY_ERROR;
3482234824

@@ -34838,26 +34840,33 @@ int SetTicket(WOLFSSL* ssl, const byte* ticket, word32 length)
3483834840
ssl->session->ticketLen = (word16)length;
3483934841

3484034842
if (length > 0) {
34843+
if (length < ID_LEN)
34844+
sessIdLen = length;
3484134845
XMEMCPY(ssl->session->ticket, ticket, length);
3484234846
if (ssl->session_ticket_cb != NULL) {
3484334847
ssl->session_ticket_cb(ssl,
34844-
ssl->session->ticket, ssl->session->ticketLen,
34848+
ssl->session->ticket,
34849+
ssl->session->ticketLen,
3484534850
ssl->session_ticket_ctx);
3484634851
}
3484734852
/* Create a fake sessionID based on the ticket, this will
3484834853
* supersede the existing session cache info. */
3484934854
ssl->options.haveSessionId = 1;
3485034855
#ifdef WOLFSSL_TLS13
3485134856
if (ssl->options.tls1_3) {
34857+
XMEMSET(ssl->session->sessionID, 0, ID_LEN);
3485234858
XMEMCPY(ssl->session->sessionID,
34853-
ssl->session->ticket + length - ID_LEN, ID_LEN);
34859+
ssl->session->ticket + length - sessIdLen,
34860+
sessIdLen);
3485434861
ssl->session->sessionIDSz = ID_LEN;
3485534862
}
3485634863
else
3485734864
#endif
3485834865
{
34866+
XMEMSET(ssl->arrays->sessionID, 0, ID_LEN);
3485934867
XMEMCPY(ssl->arrays->sessionID,
34860-
ssl->session->ticket + length - ID_LEN, ID_LEN);
34868+
ssl->session->ticket + length - sessIdLen,
34869+
sessIdLen);
3486134870
ssl->arrays->sessionIDSz = ID_LEN;
3486234871
}
3486334872
}

0 commit comments

Comments
 (0)