@@ -1180,6 +1180,8 @@ static int ImportKeyState(WOLFSSL* ssl, const byte* exp, word32 len, byte ver,
11801180 word16 i, wordCount, wordAdj = 0;
11811181
11821182 /* do window */
1183+ if (idx + OPAQUE16_LEN > len)
1184+ return BUFFER_E;
11831185 ato16(exp + idx, &wordCount);
11841186 idx += OPAQUE16_LEN;
11851187
@@ -1188,6 +1190,8 @@ static int ImportKeyState(WOLFSSL* ssl, const byte* exp, word32 len, byte ver,
11881190 wordCount = WOLFSSL_DTLS_WINDOW_WORDS;
11891191 }
11901192
1193+ if (idx + (wordCount * OPAQUE32_LEN) + wordAdj > len)
1194+ return BUFFER_E;
11911195 XMEMSET(keys->peerSeq[0].window, 0xFF, DTLS_SEQ_SZ);
11921196 for (i = 0; i < wordCount; i++) {
11931197 ato32(exp + idx, &keys->peerSeq[0].window[i]);
@@ -1196,6 +1200,9 @@ static int ImportKeyState(WOLFSSL* ssl, const byte* exp, word32 len, byte ver,
11961200 idx += wordAdj;
11971201
11981202 /* do prevWindow */
1203+ wordAdj = 0;
1204+ if (idx + OPAQUE16_LEN > len)
1205+ return BUFFER_E;
11991206 ato16(exp + idx, &wordCount);
12001207 idx += OPAQUE16_LEN;
12011208
@@ -1204,6 +1211,8 @@ static int ImportKeyState(WOLFSSL* ssl, const byte* exp, word32 len, byte ver,
12041211 wordCount = WOLFSSL_DTLS_WINDOW_WORDS;
12051212 }
12061213
1214+ if (idx + (wordCount * OPAQUE32_LEN) + wordAdj > len)
1215+ return BUFFER_E;
12071216 XMEMSET(keys->peerSeq[0].prevWindow, 0xFF, DTLS_SEQ_SZ);
12081217 for (i = 0; i < wordCount; i++) {
12091218 ato32(exp + idx, &keys->peerSeq[0].prevWindow[i]);
0 commit comments