From b857b3415ff9a459cbdef69e5fc85b5ed560a481 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Wed, 5 Mar 2025 17:08:36 +0400 Subject: [PATCH] Core: avoid potential underflow in ngx_gmtime(). The underflow may happen for small argument values. Normally the code is optimized by the compiler, which elimitaes the undeflow. Even if the underflow happens, the followup addition will also eliminate it. The change reorders operations to avoid the underflow in any case. Found by Coverity (CID 1605495). --- src/core/ngx_times.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c index 16788c98c..d7ef77ef5 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -360,7 +360,7 @@ ngx_gmtime(time_t t, ngx_tm_t *tp) */ /* days since March 1, 1 BC */ - days = days - (31 + 28) + 719527; + days = days + 719527 - (31 + 28); /* * The "days" should be adjusted to 1 only, however, some March 1st's go