From e34ccaf4817613563ce616fdb20d060bf6d47507 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Wed, 9 Sep 2020 23:23:32 +0200 Subject: [PATCH] Fix window check If `curLT` then diff needs to be decremented. For example: `diff` = 1 represents last packet so it would be the `window[idx] & (1 << 0)` bit of the window variable. --- src/internal.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 17c6c0cf7..72b9dd2f1 100644 --- a/src/internal.c +++ b/src/internal.c @@ -12906,8 +12906,15 @@ static WC_INLINE int DtlsCheckWindow(WOLFSSL* ssl) } #endif else if (curLT) { - word32 idx = diff / DTLS_WORD_BITS; - word32 newDiff = diff % DTLS_WORD_BITS; + word32 idx; + word32 newDiff; + if (diff == 0) { + WOLFSSL_MSG("DTLS sanity check failed"); + return 0; + } + diff--; + idx = diff / DTLS_WORD_BITS; + newDiff = diff % DTLS_WORD_BITS; /* verify idx is valid for window array */ if (idx >= WOLFSSL_DTLS_WINDOW_WORDS) {