diff --git a/src/internal.c b/src/internal.c index d8a44acf6..7208feb81 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7224,8 +7224,8 @@ DtlsMsg* DtlsMsgInsert(DtlsMsg* head, DtlsMsg* item) DtlsMsg* cur = head->next; DtlsMsg* prev = head; while (cur) { - if (item->epoch <= head->epoch && - item->seq < head->seq) { + if (item->epoch <= cur->epoch && + item->seq < cur->seq) { item->next = cur; prev->next = item; break; @@ -13272,11 +13272,11 @@ static WC_INLINE int DtlsUpdateWindow(WOLFSSL* ssl) if (cur_hi == *next_hi) { curLT = cur_lo < *next_lo; - diff = curLT ? *next_lo - cur_lo : cur_lo - *next_lo; + diff = curLT ? *next_lo - cur_lo - 1 : cur_lo - *next_lo + 1; } else { curLT = cur_hi < *next_hi; - diff = curLT ? cur_lo - *next_lo : *next_lo - cur_lo; + diff = curLT ? cur_lo - *next_lo - 1 : *next_lo - cur_lo + 1; } if (curLT) { @@ -13294,7 +13294,6 @@ static WC_INLINE int DtlsUpdateWindow(WOLFSSL* ssl) word32 oldWindow[WOLFSSL_DTLS_WINDOW_WORDS]; temp = 0; - diff++; idx = diff / DTLS_WORD_BITS; newDiff = diff % DTLS_WORD_BITS;