@@ -17040,8 +17040,23 @@ static int _DtlsUpdateWindow(WOLFSSL* ssl)
1704017040 next_hi, next_lo, window);
1704117041}
1704217042
17043+ static WC_INLINE int DtlsShouldUpdateWindow(int ret)
17044+ {
17045+ switch (ret) {
17046+ case 0:
17047+ #ifdef WOLFSSL_ASYNC_CRYPT
17048+ case WC_PENDING_E:
17049+ #endif
17050+ case APP_DATA_READY:
17051+ return 1;
17052+ default:
17053+ return 0;
17054+ }
17055+ }
17056+
1704317057#ifdef WOLFSSL_DTLS13
17044- static WC_INLINE int Dtls13UpdateWindow(WOLFSSL* ssl)
17058+
17059+ static int Dtls13UpdateWindow(WOLFSSL* ssl)
1704517060{
1704617061 w64wrapper nextSeq, seq;
1704717062 w64wrapper diff64;
@@ -17104,6 +17119,14 @@ static WC_INLINE int Dtls13UpdateWindow(WOLFSSL* ssl)
1710417119
1710517120 return 0;
1710617121}
17122+
17123+ static WC_INLINE int Dtls13UpdateWindowRecordRecvd(WOLFSSL* ssl)
17124+ {
17125+ int ret = Dtls13UpdateWindow(ssl);
17126+ if (ret != 0)
17127+ return ret;
17128+ return Dtls13RecordRecvd(ssl);
17129+ }
1710717130#endif /* WOLFSSL_DTLS13 */
1710817131
1710917132int DtlsMsgDrain(WOLFSSL* ssl)
@@ -20805,7 +20828,8 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2080520828 ssl->buffers.inputBuffer.buffer,
2080620829 &ssl->buffers.inputBuffer.idx,
2080720830 ssl->buffers.inputBuffer.length);
20808- if (ret == 0 && ssl->options.dtlsStateful) {
20831+ if (DtlsShouldUpdateWindow(ret) &&
20832+ ssl->options.dtlsStateful) {
2080920833 if (IsDtlsNotSctpMode(ssl))
2081020834 _DtlsUpdateWindow(ssl);
2081120835 /* Reset timeout as we have received a valid
@@ -20826,16 +20850,13 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2082620850 ssl->buffers.inputBuffer.buffer,
2082720851 &ssl->buffers.inputBuffer.idx,
2082820852 ssl->buffers.inputBuffer.length);
20829- if (ret == 0 && ssl->options.dtlsStateful) {
20830- ret = Dtls13UpdateWindow(ssl);
20831- if (ret != 0) {
20832- WOLFSSL_ERROR(ret);
20833- return ret;
20834- }
20835- ret = Dtls13RecordRecvd(ssl);
20836- if (ret != 0) {
20837- WOLFSSL_ERROR(ret);
20838- return ret;
20853+ if (DtlsShouldUpdateWindow(ret) &&
20854+ ssl->options.dtlsStateful) {
20855+ int updateRet =
20856+ Dtls13UpdateWindowRecordRecvd(ssl);
20857+ if (updateRet != 0) {
20858+ WOLFSSL_ERROR(updateRet);
20859+ return updateRet;
2083920860 }
2084020861 }
2084120862#ifdef WOLFSSL_EARLY_DATA
@@ -20960,12 +20981,7 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2096020981 }
2096120982#ifdef WOLFSSL_DTLS13
2096220983 if (ssl->options.dtls) {
20963- ret = Dtls13UpdateWindow(ssl);
20964- if (ret != 0) {
20965- WOLFSSL_ERROR(ret);
20966- return ret;
20967- }
20968- ret = Dtls13RecordRecvd(ssl);
20984+ ret = Dtls13UpdateWindowRecordRecvd(ssl);
2096920985 if (ret != 0) {
2097020986 WOLFSSL_ERROR(ret);
2097120987 return ret;
@@ -21126,16 +21142,10 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2112621142 ssl->buffers.inputBuffer.buffer,
2112721143 &ssl->buffers.inputBuffer.idx, NO_SNIFF);
2112821144#ifdef WOLFSSL_DTLS
21129- if (ssl->options.dtls &&
21130- (ret == 0 || ret == APP_DATA_READY)) {
21145+ if (ssl->options.dtls && DtlsShouldUpdateWindow(ret)) {
2113121146#ifdef WOLFSSL_DTLS13
2113221147 if (IsAtLeastTLSv1_3(ssl->version)) {
21133- int updateRet = Dtls13UpdateWindow(ssl);
21134- if (updateRet != 0) {
21135- WOLFSSL_ERROR(updateRet);
21136- return updateRet;
21137- }
21138- updateRet = Dtls13RecordRecvd(ssl);
21148+ int updateRet = Dtls13UpdateWindowRecordRecvd(ssl);
2113921149 if (updateRet != 0) {
2114021150 WOLFSSL_ERROR(updateRet);
2114121151 return updateRet;
@@ -21180,12 +21190,7 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2118021190 if (ssl->options.dtls) {
2118121191#ifdef WOLFSSL_DTLS13
2118221192 if (IsAtLeastTLSv1_3(ssl->version)) {
21183- ret = Dtls13UpdateWindow(ssl);
21184- if (ret != 0) {
21185- WOLFSSL_ERROR(ret);
21186- return ret;
21187- }
21188- ret = Dtls13RecordRecvd(ssl);
21193+ ret = Dtls13UpdateWindowRecordRecvd(ssl);
2118921194 if (ret != 0) {
2119021195 WOLFSSL_ERROR(ret);
2119121196 return ret;
@@ -21211,18 +21216,15 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2121121216 ssl->keys.padSz, &processedSize);
2121221217 ssl->buffers.inputBuffer.idx += processedSize;
2121321218 ssl->buffers.inputBuffer.idx += ssl->keys.padSz;
21214- if (ret != 0)
21215- return ret ;
21216- ret = Dtls13UpdateWindow(ssl);
21217- if (ret != 0) {
21218- WOLFSSL_ERROR(ret) ;
21219- return ret;
21219+ if (DtlsShouldUpdateWindow( ret)) {
21220+ int updateRet = Dtls13UpdateWindowRecordRecvd(ssl) ;
21221+ if (updateRet != 0) {
21222+ WOLFSSL_ERROR(updateRet);
21223+ return updateRet ;
21224+ }
2122021225 }
21221- ret = Dtls13RecordRecvd(ssl);
21222- if (ret != 0) {
21223- WOLFSSL_ERROR(ret);
21226+ if (ret != 0)
2122421227 return ret;
21225- }
2122621228 break;
2122721229 }
2122821230 FALL_THROUGH;
0 commit comments