@@ -1222,39 +1222,44 @@ static int Dtls13GotTimeout(WOLFSSL* ssl, int expired)
12221222/* Get the time left on the DTLS timers.
12231223 *
12241224 * @param [in] ssl SSL/TLS object.
1225+ * @param [out] running 1 when a timer runs, 0 otherwise.
12251226 * @param [out] left Milliseconds until the first timer expires.
12261227 * @param [out] ackOnly 1 when only the DTLS 1.3 ack timer expired.
1227- * @return 1 when a timer runs.
1228- * @return 0 when no timer runs.
1228+ * @return 0 on success.
12291229 * @return BAD_MUTEX_E when locking fails.
12301230 */
1231- static int DtlsTimerLeft (WOLFSSL * ssl , word32 * left , int * ackOnly )
1231+ static int DtlsTimerLeft (WOLFSSL * ssl , int * running , word32 * left ,
1232+ int * ackOnly )
12321233{
12331234#ifndef NO_ASN_TIME
1234- int running ;
1235+ int ret ;
1236+ int timers = 0 ;
12351237 word32 timeout ;
12361238 word32 elapsed ;
12371239#ifdef WOLFSSL_DTLS13
12381240 word32 ackLeft ;
12391241#endif
12401242 word32 ackStart = 0 ;
12411243
1244+ * running = 0 ;
12421245 if (!IsDtlsNotSctpMode (ssl ) || ssl -> dtls_timeout <= 0 ||
12431246 ssl -> buffers .outputBuffer .length > 0 )
12441247 return 0 ;
1245- running = DtlsTimersRunning (ssl , & ackStart );
1248+ ret = DtlsTimersRunning (ssl , & timers , & ackStart );
1249+ if (ret != 0 )
1250+ return ret ;
12461251#ifdef WOLFSSL_HAVE_HS_SUSPEND
12471252 /* A suspended handshake has not finished sending its flight. */
1248- if (running > 0 && IsHsSuspendErr (ssl -> error ))
1249- running &= ~DTLS_TIMER_RTX ;
1253+ if (IsHsSuspendErr (ssl -> error ))
1254+ timers &= ~DTLS_TIMER_RTX ;
12501255#endif
1251- if (running < = 0 )
1252- return running ;
1256+ if (timers = = 0 )
1257+ return 0 ;
12531258
12541259 timeout = DtlsTimerTimeoutMs (ssl );
12551260 * left = timeout ;
12561261 * ackOnly = 1 ;
1257- if (running & DTLS_TIMER_RTX ) {
1262+ if (timers & DTLS_TIMER_RTX ) {
12581263 elapsed = DtlsTimerElapsedMs (ssl -> dtls_timer_start );
12591264 * left = (elapsed < timeout ) ? timeout - elapsed : 0 ;
12601265#ifdef WOLFSSL_DTLS13
@@ -1264,16 +1269,18 @@ static int DtlsTimerLeft(WOLFSSL* ssl, word32* left, int* ackOnly)
12641269 * ackOnly = (* left > 0 );
12651270 }
12661271#ifdef WOLFSSL_DTLS13
1267- if (running & DTLS_TIMER_ACK ) {
1272+ if (timers & DTLS_TIMER_ACK ) {
12681273 elapsed = DtlsTimerNowMs () - ackStart ;
12691274 ackLeft = (elapsed < timeout / 4 ) ? timeout / 4 - elapsed : 0 ;
1270- if (ackLeft < * left || !(running & DTLS_TIMER_RTX ))
1275+ if (ackLeft < * left || !(timers & DTLS_TIMER_RTX ))
12711276 * left = ackLeft ;
12721277 }
12731278#endif
1274- return 1 ;
1279+ * running = 1 ;
1280+ return 0 ;
12751281#else
12761282 (void )ssl ;
1283+ * running = 0 ;
12771284 (void )left ;
12781285 (void )ackOnly ;
12791286 return 0 ;
@@ -1291,16 +1298,17 @@ int wolfSSL_DTLSv1_get_timeout(WOLFSSL* ssl, WOLFSSL_TIMEVAL* timeleft)
12911298{
12921299 word32 left = 0 ;
12931300 int ackOnly = 0 ;
1301+ int running = 0 ;
12941302 int ret ;
12951303
12961304 if (ssl == NULL || timeleft == NULL )
12971305 return 0 ;
12981306
12991307 XMEMSET (timeleft , 0 , sizeof (WOLFSSL_TIMEVAL ));
1300- ret = DtlsTimerLeft (ssl , & left , & ackOnly );
1301- if (ret < 0 )
1308+ ret = DtlsTimerLeft (ssl , & running , & left , & ackOnly );
1309+ if (ret != 0 )
13021310 WOLFSSL_MSG ("Getting the DTLS timers failed" );
1303- if (ret < = 0 )
1311+ if (ret ! = 0 || ! running )
13041312 return 0 ;
13051313
13061314 timeleft -> tv_sec = left / 1000 ;
@@ -1322,18 +1330,19 @@ int wolfSSL_DTLSv1_handle_timeout(WOLFSSL* ssl)
13221330{
13231331 word32 left = 0 ;
13241332 int ackOnly = 0 ;
1333+ int running = 0 ;
13251334 int ret ;
13261335
13271336 if (ssl == NULL )
13281337 return WOLFSSL_FATAL_ERROR ;
13291338
1330- ret = DtlsTimerLeft (ssl , & left , & ackOnly );
1331- if (ret < 0 ) {
1339+ ret = DtlsTimerLeft (ssl , & running , & left , & ackOnly );
1340+ if (ret != 0 ) {
13321341 ssl -> error = ret ;
13331342 WOLFSSL_ERROR (ret );
13341343 return WOLFSSL_FATAL_ERROR ;
13351344 }
1336- if (ret == 0 || left > 0 )
1345+ if (! running || left > 0 )
13371346 return 0 ;
13381347
13391348#ifdef WOLFSSL_DTLS13
0 commit comments