diff --git a/dtls.c b/dtls.c index 97ad5b0e..3929645e 100644 --- a/dtls.c +++ b/dtls.c @@ -4702,7 +4702,8 @@ dtls_check_retransmit(dtls_context_t *context, clock_time_t *next) { netq_t *node = netq_head(&context->sendqueue); dtls_ticks(&now); - while (node && node->t <= now) { + // comparison considering 32bit overflow + while (node && DTLS_IS_BEFORE_TIME(node->t, now)) { netq_pop_first(&context->sendqueue); dtls_retransmit(context, node); node = netq_head(&context->sendqueue); diff --git a/dtls_time.h b/dtls_time.h index f9974327..252a4530 100644 --- a/dtls_time.h +++ b/dtls_time.h @@ -51,6 +51,7 @@ #endif typedef uint64_t clock_time_t; + #else /* WITH_CONTIKI || RIOT_VERSION */ #ifdef HAVE_TIME_H @@ -62,6 +63,7 @@ typedef uint64_t clock_time_t; #endif typedef uint32_t clock_time_t; + #endif /* WITH_CONTIKI || RIOT_VERSION */ typedef clock_time_t dtls_tick_t; @@ -73,6 +75,11 @@ typedef clock_time_t dtls_tick_t; void dtls_clock_init(void); void dtls_ticks(dtls_tick_t *t); +// see https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1AB9U8lJL6yAngGVG6AMKpaAVxYMJG0g4AyeBkwAOXcAI0xiEAA2UgAHVAVCWwZnNw8vOISkgX9AkJZwyJjLTGtkoQImYgJU908ubxKygQqqglzgsIjoi0rq2vSG3raO/MLogEoLVFdiZHYOAFIAJgBmAOQ3LABqRdXHBQJ8VAA6BD3sRY0AQRX1hk3XHb2Do4CCM4ur25u7rBpAtsACpBYwAeQAYhChNggdsIABWDQTb7fAgAT1imH%2B21c7wAHMYCNtNqhkABrIl4NhEvYAIVRN3e2xYTACEAAbqg8OgUQB2Bk3bbC7Zcgw2egk2hkyk2GnE4l7AAi2w09O%2BItFLiYEswUplVPl2wYu1WKrVq0F101aAYh31FMNmCJLKYwDwyGMqCoVCUirN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gJgYyxhoV%2BXA%2BTY0kKsfEGg%2BTLD5AATlWNIYmpNSDg0hhfKmNMUZoymEzKAMBEAgCIC4LmEAqjABNrwRhChlCGFtkIBALUfakB5sAvQ2Jv6LyjsIUQ4h46iKTmocmLABBMDQF/IgxAAASTAFB0kPgwa4ltUBh0YNiXhcjmCKPwMo/REdeDGIUagCo%2BBLG9HsZTRxAR2GBFoFwlqDjaG0AAJLoBALEJg3D6CkD7M7WIPsT4cFBvg8mF8gkhMRn/aShAEDbCvjfO%2BD8n4Ji4K/cBZDoHY1xgTMp2N9CcDwd7JEcTz7OOprTMhjMqEQCQDMAgsRLb0P4XzQRZiSB6FETHCR0gpFKBkZrcJTBIncAZsTWJBDeAXzBJbLpxJvQZOvrfe%2Bj9n75LfoA3mERf6rETIU%2BmUDSAIEwEwLAkQIDROqSAWpSyKYcGIU0y5xSognEkJILBqx4r4gRFg/ECDKkcHLnUwhziIHo0hcsM%2BsKPmkO%2BaQRqiQ7CSCAA%3D +#define DTLS_OFFSET_TIME (((clock_time_t)~0) >> 1) +/** Checks if A is before (or equal) B. Considers 32 bit time overflow */ +#define DTLS_IS_BEFORE_TIME(A, B) ((DTLS_OFFSET_TIME + (B)-(A)) >= DTLS_OFFSET_TIME) + /** @} */ #endif /* _DTLS_DTLS_TIME_H_ */ diff --git a/netq.c b/netq.c index 06754f7a..b2195cd2 100644 --- a/netq.c +++ b/netq.c @@ -93,7 +93,8 @@ netq_insert_node(netq_t **queue, netq_t *node) { assert(node); p = *queue; - while(p && p->t <= node->t) { + // comparison considering 32bit overflow + while(p && DTLS_IS_BEFORE_TIME(p->t, node->t)) { assert(p != node); if (p == node) return 0;