diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-04 20:00:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-04 20:01:36 +0200 |
commit | fc5067afd287b951b07b00e39126562164f29207 (patch) | |
tree | 8a40357fe7a973e10e87fdf7c4236acbec59765c | |
parent | 53d0ca2ad8ad8ee1094da9ec1152e6b1cf7fb321 (diff) | |
download | serenity-fc5067afd287b951b07b00e39126562164f29207.zip |
ProtocolServer+LibProtocol: Reject unhandled URLs instead of asserting
StartDownload requests for unhandled protocols (or invalid URLs) will
now refuse to load instead of asserting. A failure code is sent back
to LibProtocol and Protocol::Client::start_download() returns nullptr.
Fixes #1604.
-rw-r--r-- | Libraries/LibProtocol/Client.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/ResourceLoader.cpp | 5 | ||||
-rw-r--r-- | Servers/ProtocolServer/PSClientConnection.cpp | 6 | ||||
-rw-r--r-- | Userland/pro.cpp | 4 |
4 files changed, 15 insertions, 2 deletions
diff --git a/Libraries/LibProtocol/Client.cpp b/Libraries/LibProtocol/Client.cpp index 2c1973291e..0b80102a8d 100644 --- a/Libraries/LibProtocol/Client.cpp +++ b/Libraries/LibProtocol/Client.cpp @@ -50,6 +50,8 @@ bool Client::is_supported_protocol(const String& protocol) RefPtr<Download> Client::start_download(const String& url) { i32 download_id = send_sync<Messages::ProtocolServer::StartDownload>(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 c6b1aac24c..7ef40f5cf5 100644 --- a/Libraries/LibWeb/ResourceLoader.cpp +++ b/Libraries/LibWeb/ResourceLoader.cpp @@ -86,6 +86,11 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> 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 e788e190f3..b8be911f84 100644 --- a/Servers/ProtocolServer/PSClientConnection.cpp +++ b/Servers/ProtocolServer/PSClientConnection.cpp @@ -57,9 +57,11 @@ OwnPtr<Messages::ProtocolServer::IsSupportedProtocolResponse> PSClientConnection OwnPtr<Messages::ProtocolServer::StartDownloadResponse> PSClientConnection::handle(const Messages::ProtocolServer::StartDownload& message) { URL url(message.url()); - ASSERT(url.is_valid()); + if (!url.is_valid()) + return make<Messages::ProtocolServer::StartDownloadResponse>(-1); auto* protocol = Protocol::find_by_name(url.protocol()); - ASSERT(protocol); + if (!protocol) + return make<Messages::ProtocolServer::StartDownloadResponse>(-1); auto download = protocol->start_download(*this, url); return make<Messages::ProtocolServer::StartDownloadResponse>(download->id()); } diff --git a/Userland/pro.cpp b/Userland/pro.cpp index 788e42427f..51d0b4912f 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); }; |