[njs] Fixed Date constructor for overflows and with NaN values.

Dmitry Volyntsev xeioex at nginx.com
Tue Jan 9 00:57:11 UTC 2024


details:   https://hg.nginx.org/njs/rev/57071ecadeb5
branches:  
changeset: 2251:57071ecadeb5
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Jan 08 16:40:27 2024 -0800
description:
Fixed Date constructor for overflows and with NaN values.

Found by UndefinedBehaviorSanitizer.

diffstat:

 src/njs_date.c |  8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diffs (23 lines):

diff -r 4a15613f4e8b -r 57071ecadeb5 src/njs_date.c
--- a/src/njs_date.c	Tue Dec 19 12:37:05 2023 -0800
+++ b/src/njs_date.c	Mon Jan 08 16:40:27 2024 -0800
@@ -243,11 +243,19 @@ njs_make_date(int64_t tm[], njs_bool_t l
     days = njs_make_day(tm[NJS_DATE_YR], tm[NJS_DATE_MON],
                         tm[NJS_DATE_DAY]);
 
+    if (njs_slow_path(isnan(days))) {
+        return NAN;
+    }
+
     time = ((tm[NJS_DATE_HR] * 60.0 + tm[NJS_DATE_MIN]) * 60.0
             + tm[NJS_DATE_SEC]) * 1000.0 + tm[NJS_DATE_MSEC];
 
     time += days * 86400000.0;
 
+    if (time < -8.64e15 || time > 8.64e15) {
+        return NAN;
+    }
+
     if (local) {
         time += njs_tz_offset(time) * 60000;
     }


More information about the nginx-devel mailing list