LibWeb: Don't crash when handling invalid HTTP status codes

Example crash: https://wpt.live/fetch/h1-parsing/status-code.window.html

There is still work to make the above tests pass.
This commit is contained in:
Callum Law 2025-05-25 16:00:28 +12:00 committed by Andrew Kaster
parent 24da7b006e
commit 6c3ceb9284
Notes: github-actions[bot] 2025-05-27 18:59:12 +00:00

View file

@ -443,8 +443,12 @@ void ResourceLoader::load(LoadRequest& request, GC::Root<SuccessCallback> succes
else
error_builder.append("Load failed"sv);
if (status_code.has_value() && *status_code > 0)
error_builder.appendff(" (status: {} {})", *status_code, HTTP::HttpResponse::reason_phrase_for_code(*status_code));
if (status_code.has_value()) {
if (*status_code >= 100 && *status_code <= 599)
error_builder.appendff(" (status: {} {})", *status_code, HTTP::HttpResponse::reason_phrase_for_code(*status_code));
else
error_builder.appendff(" (status: {})", *status_code);
}
log_failure(request, error_builder.string_view());
if (error_callback)