From 1dce1994eb382ae6d80799450f8619482903116b Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Thu, 29 Jun 2023 20:41:37 +0200 Subject: [PATCH] LibJS: Make the options arg of InterpretTemporalDateTimeFields nullable This fixes "reference binding to null pointer" UBSan warnings. --- .../LibJS/Runtime/Temporal/AbstractOperations.cpp | 2 +- .../Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp | 8 ++++---- Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h | 2 +- .../LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp | 2 +- .../LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 82e279c65d9..f15c4f83af0 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -605,7 +605,7 @@ ThrowCompletionOr to_relative_temporal_object(VM& vm, Object const& optio MUST(date_options->create_data_property_or_throw(vm.names.overflow, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "constrain"sv)))); // h. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, dateOptions). - result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *date_options)); + result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, date_options)); // i. Let offsetString be ? Get(value, "offset"). offset_string = TRY(value_object.get(vm.names.offset)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index cb0a4ff69d4..537345ca309 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -75,16 +75,16 @@ bool iso_date_time_within_limits(i32 year, u8 month, u8 day, u8 hour, u8 minute, } // 5.5.2 InterpretTemporalDateTimeFields ( calendar, fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-interprettemporaldatetimefields -ThrowCompletionOr interpret_temporal_date_time_fields(VM& vm, Object& calendar, Object& fields, Object const& options) +ThrowCompletionOr interpret_temporal_date_time_fields(VM& vm, Object& calendar, Object& fields, Object const* options) { // 1. Let timeResult be ? ToTemporalTimeRecord(fields). auto unregulated_time_result = TRY(to_temporal_time_record(vm, fields)); // 2. Let overflow be ? ToTemporalOverflow(options). - auto overflow = TRY(to_temporal_overflow(vm, &options)); + auto overflow = TRY(to_temporal_overflow(vm, options)); // 3. Let temporalDate be ? CalendarDateFromFields(calendar, fields, options). - auto* temporal_date = TRY(calendar_date_from_fields(vm, calendar, fields, &options)); + auto* temporal_date = TRY(calendar_date_from_fields(vm, calendar, fields, options)); // 4. Let timeResult be ? RegulateTime(timeResult.[[Hour]], timeResult.[[Minute]], timeResult.[[Second]], timeResult.[[Millisecond]], timeResult.[[Microsecond]], timeResult.[[Nanosecond]], overflow). auto time_result = TRY(regulate_time(vm, *unregulated_time_result.hour, *unregulated_time_result.minute, *unregulated_time_result.second, *unregulated_time_result.millisecond, *unregulated_time_result.microsecond, *unregulated_time_result.nanosecond, overflow)); @@ -157,7 +157,7 @@ ThrowCompletionOr to_temporal_date_time(VM& vm, Value item, Obje auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector {})); // g. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options). - result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *options)); + result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, options)); } // 4. Else, else { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h index cb0e4dd2006..fa4c776a778 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h @@ -65,7 +65,7 @@ struct TemporalPlainDateTime { }; bool iso_date_time_within_limits(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond); -ThrowCompletionOr interpret_temporal_date_time_fields(VM&, Object& calendar, Object& fields, Object const& options); +ThrowCompletionOr interpret_temporal_date_time_fields(VM&, Object& calendar, Object& fields, Object const* options); ThrowCompletionOr to_temporal_date_time(VM&, Value item, Object const* options = nullptr); ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, i64 nanosecond); ThrowCompletionOr create_temporal_date_time(VM&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target = nullptr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp index 42da9ae4d2f..90049d115d3 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp @@ -410,7 +410,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with) fields = TRY(prepare_temporal_fields(vm, *fields, field_names, Vector {})); // 12. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options). - auto result = TRY(interpret_temporal_date_time_fields(vm, calendar, *fields, *options)); + auto result = TRY(interpret_temporal_date_time_fields(vm, calendar, *fields, options)); // 13. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true. VERIFY(is_valid_iso_date(result.year, result.month, result.day)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index 5730d01658c..0eaa50683c3 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -180,7 +180,7 @@ ThrowCompletionOr to_temporal_zoned_date_time(VM& vm, Value item } // l. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options). - result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *options)); + result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, options)); } // 6. Else, else { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp index 19162bdfc45..4d4f2d5a9b1 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp @@ -806,7 +806,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with) auto offset_string = TRY(offset_string_value.as_string().utf8_string()); // 19. Let dateTimeResult be ? InterpretTemporalDateTimeFields(calendar, fields, options). - auto date_time_result = TRY(interpret_temporal_date_time_fields(vm, calendar, *fields, *options)); + auto date_time_result = TRY(interpret_temporal_date_time_fields(vm, calendar, *fields, options)); // 20. If IsTimeZoneOffsetString(offsetString) is false, throw a RangeError exception. if (!is_time_zone_offset_string(offset_string))