diff --git a/Libraries/LibProtocol/Client.cpp b/Libraries/LibProtocol/Client.cpp index 2c1973291ef..0b80102a8d7 100644 --- a/Libraries/LibProtocol/Client.cpp +++ b/Libraries/LibProtocol/Client.cpp @@ -50,6 +50,8 @@ bool Client::is_supported_protocol(const String& protocol) RefPtr Client::start_download(const String& url) { i32 download_id = send_sync(url)->download_id(); + if (download_id < 0) + return nullptr; auto download = Download::create_from_id({}, *this, download_id); m_downloads.set(download_id, download); return download; diff --git a/Libraries/LibWeb/ResourceLoader.cpp b/Libraries/LibWeb/ResourceLoader.cpp index c6b1aac24c3..7ef40f5cf54 100644 --- a/Libraries/LibWeb/ResourceLoader.cpp +++ b/Libraries/LibWeb/ResourceLoader.cpp @@ -86,6 +86,11 @@ void ResourceLoader::load(const URL& url, Function succ if (url.protocol() == "http") { auto download = protocol_client().start_download(url.to_string()); + if (!download) { + if (error_callback) + error_callback("Failed to initiate load"); + return; + } download->on_finish = [this, success_callback = move(success_callback), error_callback = move(error_callback)](bool success, const ByteBuffer& payload, auto) { --m_pending_loads; if (on_load_counter_change) diff --git a/Servers/ProtocolServer/PSClientConnection.cpp b/Servers/ProtocolServer/PSClientConnection.cpp index e788e190f3f..b8be911f841 100644 --- a/Servers/ProtocolServer/PSClientConnection.cpp +++ b/Servers/ProtocolServer/PSClientConnection.cpp @@ -57,9 +57,11 @@ OwnPtr PSClientConnection OwnPtr PSClientConnection::handle(const Messages::ProtocolServer::StartDownload& message) { URL url(message.url()); - ASSERT(url.is_valid()); + if (!url.is_valid()) + return make(-1); auto* protocol = Protocol::find_by_name(url.protocol()); - ASSERT(protocol); + if (!protocol) + return make(-1); auto download = protocol->start_download(*this, url); return make(download->id()); } diff --git a/Userland/pro.cpp b/Userland/pro.cpp index 788e42427f7..51d0b4912f2 100644 --- a/Userland/pro.cpp +++ b/Userland/pro.cpp @@ -49,6 +49,10 @@ int main(int argc, char** argv) auto protocol_client = Protocol::Client::construct(); auto download = protocol_client->start_download(url.to_string()); + if (!download) { + fprintf(stderr, "Failed to start download for '%s'\n", url_string.characters()); + return 1; + } download->on_progress = [](u32 total_size, u32 downloaded_size) { dbgprintf("download progress: %u / %u\n", downloaded_size, total_size); };