]> git.kaiwu.me - njs.git/commitdiff
Fixed Date constructor for overflows and with NaN values.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 9 Jan 2024 00:40:27 +0000 (16:40 -0800)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 9 Jan 2024 00:40:27 +0000 (16:40 -0800)
Found by UndefinedBehaviorSanitizer.

src/njs_date.c

index 788ed41d27424b447ade84d2dadb08bfe2ba5e7c..8f0850abe3db038e5c12d684bd0b34b063488cbe 100644 (file)
@@ -243,11 +243,19 @@ njs_make_date(int64_t tm[], njs_bool_t local)
     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;
     }