aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2025-03-10 12:19:25 +0400
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>2025-04-15 19:01:36 +0400
commit1e883a40db98b70e422ff8e4d1d0e87e3f8ccaa5 (patch)
tree2eb1f21e6e3cad971c16534c482b21f0cadc633e
parent38236bf74f3e5728eeea488bef381c61842ac1d2 (diff)
downloadnginx-1e883a40db98b70e422ff8e4d1d0e87e3f8ccaa5.tar.gz
nginx-1e883a40db98b70e422ff8e4d1d0e87e3f8ccaa5.zip
QUIC: ngx_msec_t overflow protection.
On some systems the value of ngx_current_msec is derived from monotonic clock, for which the following is defined by POSIX: For this clock, the value returned by clock_gettime() represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past. As as result, overflow protection is needed when comparing two ngx_msec_t. The change adds such protection to the ngx_quic_detect_lost() function.
-rw-r--r--src/event/quic/ngx_event_quic_ack.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/event/quic/ngx_event_quic_ack.c b/src/event/quic/ngx_event_quic_ack.c
index 29c5bfed1..a6f34348b 100644
--- a/src/event/quic/ngx_event_quic_ack.c
+++ b/src/event/quic/ngx_event_quic_ack.c
@@ -449,9 +449,10 @@ ngx_quic_detect_lost(ngx_connection_t *c, ngx_quic_ack_stat_t *st)
now = ngx_current_msec;
thr = ngx_quic_lost_threshold(qc);
- /* send time of lost packets across all send contexts */
- oldest = NGX_TIMER_INFINITE;
- newest = NGX_TIMER_INFINITE;
+#if (NGX_SUPPRESS_WARN)
+ oldest = now;
+ newest = now;
+#endif
nlost = 0;
@@ -484,13 +485,17 @@ ngx_quic_detect_lost(ngx_connection_t *c, ngx_quic_ack_stat_t *st)
break;
}
- if (start->send_time > qc->first_rtt) {
+ if ((ngx_msec_int_t) (start->send_time - qc->first_rtt) > 0) {
- if (oldest == NGX_TIMER_INFINITE || start->send_time < oldest) {
+ if (nlost == 0
+ || (ngx_msec_int_t) (start->send_time - oldest) < 0)
+ {
oldest = start->send_time;
}
- if (newest == NGX_TIMER_INFINITE || start->send_time > newest) {
+ if (nlost == 0
+ || (ngx_msec_int_t) (start->send_time - newest) > 0)
+ {
newest = start->send_time;
}
@@ -511,8 +516,9 @@ ngx_quic_detect_lost(ngx_connection_t *c, ngx_quic_ack_stat_t *st)
* latest ACK frame.
*/
- if (st && nlost >= 2 && (st->newest < oldest || st->oldest > newest)) {
-
+ if (st && nlost >= 2 && ((ngx_msec_int_t) (st->newest - oldest) < 0
+ || (ngx_msec_int_t) (st->oldest - newest) > 0))
+ {
if (newest - oldest > ngx_quic_pcg_duration(c)) {
ngx_quic_persistent_congestion(c);
}