From ee608f58eebcfa5e3f78be0ffbfc9475999026b3 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 19 Aug 2021 19:17:47 +0300 Subject: LibJS: Add type range checks to the Date make_day AO As the specification says "but if this is not possible (because some argument is out of range), return NaN." --- Userland/Libraries/LibJS/Runtime/Date.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Userland/Libraries/LibJS') diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 1e1950c7df..b51808dd99 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -339,9 +339,11 @@ Value make_day(GlobalObject& global_object, Value year, Value month, Value date) // NOTE: This calculation has no side-effects and is unused, so we omit it // 8. Find a finite time value t such that YearFromTime(t) is ym and MonthFromTime(t) is mn and DateFromTime(t) is 1𝔽; but if this is not possible (because some argument is out of range), return NaN. - auto t = Core::DateTime::create(y, m + 1, 0).timestamp() * 1000; + if (!AK::is_within_range(y) || !AK::is_within_range(m + 1)) + return js_nan(); + auto t = Core::DateTime::create(static_cast(y), static_cast(m + 1), 0).timestamp() * 1000; // 9. Return Day(t) + dt - 1𝔽. - return Value(day(t) + dt - 1); + return Value(day(static_cast(t)) + dt - 1); } // 21.4.1.13 MakeDate ( day, time ), https://tc39.es/ecma262/#sec-makedate -- cgit v1.2.3