diff --git a/src/internal.c b/src/internal.c index fd82be8738..c009452d62 100644 --- a/src/internal.c +++ b/src/internal.c @@ -19088,6 +19088,8 @@ static int DoHandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx, /* curSize has already been reduced to content-only (padSz subtracted) * in ProcessReply, so curStartIdx + curSize bounds the content. */ + if (*inOutIdx > (word32)ssl->curStartIdx + ssl->curSize) + return BUFFER_ERROR; inputLength = ssl->curStartIdx + ssl->curSize - *inOutIdx; /* If there is a pending fragmented handshake message, diff --git a/src/tls13.c b/src/tls13.c index 5137ad8133..a3ad1eacf5 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -13936,6 +13936,8 @@ int DoTls13HandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx, /* curSize has already been reduced to content-only (padSz subtracted) * in ProcessReply, so curStartIdx + curSize bounds the content. */ + if (*inOutIdx > (word32)ssl->curStartIdx + ssl->curSize) + return BUFFER_ERROR; inputLength = ssl->curStartIdx + ssl->curSize - *inOutIdx; /* If there is a pending fragmented handshake message,