summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorleeight <leeight@gmail.com>2022-10-13 20:03:15 +0800
committerLinus Groh <mail@linusgroh.de>2022-10-14 11:42:36 +0200
commitbb39f70efcd0713b6202ea8cd953759f30bbe4d2 (patch)
tree2309d57ab78261eb903d1f16f1d31c50fd2c63b5 /Userland
parent30be638fb2aa0f6653e6fa2d814f40912ac54946 (diff)
downloadserenity-bb39f70efcd0713b6202ea8cd953759f30bbe4d2.zip
WindowServer: Avoid `window` nullptr exception
If `window` is nullptr, we should return as soon as possible to avoid segment fault runtime error.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Services/WindowServer/ConnectionFromClient.cpp58
1 files changed, 39 insertions, 19 deletions
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp
index 43e2e8bd97..1c3212bd36 100644
--- a/Userland/Services/WindowServer/ConnectionFromClient.cpp
+++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp
@@ -1277,17 +1277,23 @@ void ConnectionFromClient::set_flash_flush(bool enabled)
void ConnectionFromClient::set_window_parent_from_client(i32 client_id, i32 parent_id, i32 child_id)
{
- auto child_window = window_from_id(child_id);
- if (!child_window)
+ auto* child_window = window_from_id(child_id);
+ if (!child_window) {
did_misbehave("SetWindowParentFromClient: Bad child window ID");
+ return;
+ }
- auto client_connection = from_client_id(client_id);
- if (!client_connection)
+ auto* client_connection = from_client_id(client_id);
+ if (!client_connection) {
did_misbehave("SetWindowParentFromClient: Bad client ID");
+ return;
+ }
- auto parent_window = client_connection->window_from_id(parent_id);
- if (!parent_window)
+ auto* parent_window = client_connection->window_from_id(parent_id);
+ if (!parent_window) {
did_misbehave("SetWindowParentFromClient: Bad parent window ID");
+ return;
+ }
if (parent_window->is_stealable_by_client(this->client_id())) {
child_window->set_parent_window(*parent_window);
@@ -1298,34 +1304,44 @@ void ConnectionFromClient::set_window_parent_from_client(i32 client_id, i32 pare
Messages::WindowServer::GetWindowRectFromClientResponse ConnectionFromClient::get_window_rect_from_client(i32 client_id, i32 window_id)
{
- auto client_connection = from_client_id(client_id);
- if (!client_connection)
+ auto* client_connection = from_client_id(client_id);
+ if (!client_connection) {
did_misbehave("GetWindowRectFromClient: Bad client ID");
+ return { Gfx::IntRect() };
+ }
- auto window = client_connection->window_from_id(window_id);
- if (!window)
+ auto* window = client_connection->window_from_id(window_id);
+ if (!window) {
did_misbehave("GetWindowRectFromClient: Bad window ID");
+ return { Gfx::IntRect() };
+ }
return window->rect();
}
void ConnectionFromClient::add_window_stealing_for_client(i32 client_id, i32 window_id)
{
- auto window = window_from_id(window_id);
- if (!window)
+ auto* window = window_from_id(window_id);
+ if (!window) {
did_misbehave("AddWindowStealingForClient: Bad window ID");
+ return;
+ }
- if (!from_client_id(client_id))
+ if (!from_client_id(client_id)) {
did_misbehave("AddWindowStealingForClient: Bad client ID");
+ return;
+ }
window->add_stealing_for_client(client_id);
}
void ConnectionFromClient::remove_window_stealing_for_client(i32 client_id, i32 window_id)
{
- auto window = window_from_id(window_id);
- if (!window)
+ auto* window = window_from_id(window_id);
+ if (!window) {
did_misbehave("RemoveWindowStealingForClient: Bad window ID");
+ return;
+ }
// Don't check if the client exists, it may have died
@@ -1334,18 +1350,22 @@ void ConnectionFromClient::remove_window_stealing_for_client(i32 client_id, i32
void ConnectionFromClient::remove_window_stealing(i32 window_id)
{
- auto window = window_from_id(window_id);
- if (!window)
+ auto* window = window_from_id(window_id);
+ if (!window) {
did_misbehave("RemoveWindowStealing: Bad window ID");
+ return;
+ }
window->remove_all_stealing();
}
void ConnectionFromClient::set_always_on_top(i32 window_id, bool always_on_top)
{
- auto window = window_from_id(window_id);
- if (!window)
+ auto* window = window_from_id(window_id);
+ if (!window) {
did_misbehave("SetAlwaysOnTop: Bad window ID");
+ return;
+ }
window->set_always_on_top(always_on_top);
}