Check weston_head_from_resource for NULL return

If the compositor is disabling a weston_output,
weston_head_from_resource can return NULL, so the return code must be
checked where used.

Fixes #638

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
This commit is contained in:
Joshua Watt 2023-08-01 13:07:03 -06:00 committed by Marius Vlad
parent 623646bbfd
commit 617bb9afc9
6 changed files with 45 additions and 20 deletions

View file

@ -285,14 +285,15 @@ input_panel_surface_set_toplevel(struct wl_client *client,
struct input_panel_surface *input_panel_surface = struct input_panel_surface *input_panel_surface =
wl_resource_get_user_data(resource); wl_resource_get_user_data(resource);
struct desktop_shell *shell = input_panel_surface->shell; struct desktop_shell *shell = input_panel_surface->shell;
struct weston_head *head; struct weston_head *head = weston_head_from_resource(output_resource);
wl_list_insert(&shell->input_panel.surfaces, if (head) {
&input_panel_surface->link); wl_list_insert(&shell->input_panel.surfaces,
&input_panel_surface->link);
head = weston_head_from_resource(output_resource); input_panel_surface->output = head->output;
input_panel_surface->output = head->output; input_panel_surface->panel = 0;
input_panel_surface->panel = 0; }
} }
static void static void

View file

@ -2890,6 +2890,7 @@ desktop_shell_set_background(struct wl_client *client,
wl_resource_get_user_data(surface_resource); wl_resource_get_user_data(surface_resource);
struct shell_output *sh_output; struct shell_output *sh_output;
struct weston_view *view, *next; struct weston_view *view, *next;
struct weston_head *head = weston_head_from_resource(output_resource);
if (surface->committed) { if (surface->committed) {
wl_resource_post_error(surface_resource, wl_resource_post_error(surface_resource,
@ -2898,6 +2899,9 @@ desktop_shell_set_background(struct wl_client *client,
return; return;
} }
if (!head)
return;
wl_list_for_each_safe(view, next, &surface->views, surface_link) wl_list_for_each_safe(view, next, &surface->views, surface_link)
weston_view_destroy(view); weston_view_destroy(view);
view = weston_view_create(surface); view = weston_view_create(surface);
@ -2905,7 +2909,7 @@ desktop_shell_set_background(struct wl_client *client,
surface->committed = background_committed; surface->committed = background_committed;
surface->committed_private = shell; surface->committed_private = shell;
weston_surface_set_label_func(surface, background_get_label); weston_surface_set_label_func(surface, background_get_label);
surface->output = weston_head_from_resource(output_resource)->output; surface->output = head->output;
weston_view_set_output(view, surface->output); weston_view_set_output(view, surface->output);
sh_output = find_shell_output_from_weston_output(shell, surface->output); sh_output = find_shell_output_from_weston_output(shell, surface->output);
@ -2995,6 +2999,7 @@ desktop_shell_set_panel(struct wl_client *client,
wl_resource_get_user_data(surface_resource); wl_resource_get_user_data(surface_resource);
struct weston_view *view, *next; struct weston_view *view, *next;
struct shell_output *sh_output; struct shell_output *sh_output;
struct weston_head *head = weston_head_from_resource(output_resource);
if (surface->committed) { if (surface->committed) {
wl_resource_post_error(surface_resource, wl_resource_post_error(surface_resource,
@ -3003,6 +3008,9 @@ desktop_shell_set_panel(struct wl_client *client,
return; return;
} }
if (!head)
return;
wl_list_for_each_safe(view, next, &surface->views, surface_link) wl_list_for_each_safe(view, next, &surface->views, surface_link)
weston_view_destroy(view); weston_view_destroy(view);
view = weston_view_create(surface); view = weston_view_create(surface);
@ -3010,7 +3018,7 @@ desktop_shell_set_panel(struct wl_client *client,
surface->committed = panel_committed; surface->committed = panel_committed;
surface->committed_private = shell; surface->committed_private = shell;
weston_surface_set_label_func(surface, panel_get_label); weston_surface_set_label_func(surface, panel_get_label);
surface->output = weston_head_from_resource(output_resource)->output; surface->output = head->output;
weston_view_set_output(view, surface->output); weston_view_set_output(view, surface->output);
sh_output = find_shell_output_from_weston_output(shell, surface->output); sh_output = find_shell_output_from_weston_output(shell, surface->output);

View file

@ -699,7 +699,6 @@ fullscreen_shell_present_surface(struct wl_client *client,
{ {
struct fullscreen_shell *shell = struct fullscreen_shell *shell =
wl_resource_get_user_data(resource); wl_resource_get_user_data(resource);
struct weston_output *output;
struct weston_surface *surface; struct weston_surface *surface;
struct weston_seat *seat; struct weston_seat *seat;
struct fs_output *fsout; struct fs_output *fsout;
@ -720,8 +719,13 @@ fullscreen_shell_present_surface(struct wl_client *client,
} }
if (output_res) { if (output_res) {
output = weston_head_from_resource(output_res)->output; struct weston_head *head =
fsout = fs_output_for_output(output); weston_head_from_resource(output_res);
if (!head)
return;
fsout = fs_output_for_output(head->output);
fs_output_set_surface(fsout, surface, method, 0, 0); fs_output_set_surface(fsout, surface, method, 0, 0);
} else { } else {
replace_default_surface(shell, surface, method); replace_default_surface(shell, surface, method);
@ -759,13 +763,15 @@ fullscreen_shell_present_surface_for_mode(struct wl_client *client,
{ {
struct fullscreen_shell *shell = struct fullscreen_shell *shell =
wl_resource_get_user_data(resource); wl_resource_get_user_data(resource);
struct weston_output *output;
struct weston_surface *surface; struct weston_surface *surface;
struct weston_seat *seat; struct weston_seat *seat;
struct fs_output *fsout; struct fs_output *fsout;
struct weston_head *head = weston_head_from_resource(output_res);
output = weston_head_from_resource(output_res)->output; if (!head)
fsout = fs_output_for_output(output); return;
fsout = fs_output_for_output(head->output);
if (surface_res == NULL) { if (surface_res == NULL) {
fs_output_set_surface(fsout, NULL, 0, 0, 0); fs_output_set_surface(fsout, NULL, 0, 0, 0);

View file

@ -878,8 +878,10 @@ input_panel_surface_set_toplevel(struct wl_client *client,
head = weston_head_from_resource(output_resource); head = weston_head_from_resource(output_resource);
ipsurf->type = INPUT_PANEL_TOPLEVEL; if (head) {
ipsurf->output = head->output; ipsurf->type = INPUT_PANEL_TOPLEVEL;
ipsurf->output = head->output;
}
} }
static void static void

View file

@ -513,8 +513,12 @@ weston_desktop_xdg_toplevel_protocol_set_fullscreen(struct wl_client *wl_client,
weston_desktop_surface_get_implementation_data(dsurface); weston_desktop_surface_get_implementation_data(dsurface);
struct weston_output *output = NULL; struct weston_output *output = NULL;
if (output_resource != NULL) if (output_resource != NULL) {
output = weston_head_from_resource(output_resource)->output; struct weston_head *head =
weston_head_from_resource(output_resource);
if (head)
output = head->output;
}
weston_desktop_xdg_toplevel_ensure_added(toplevel); weston_desktop_xdg_toplevel_ensure_added(toplevel);
weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface, weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,

View file

@ -562,8 +562,12 @@ weston_desktop_xdg_toplevel_protocol_set_fullscreen(struct wl_client *wl_client,
weston_desktop_surface_get_implementation_data(dsurface); weston_desktop_surface_get_implementation_data(dsurface);
struct weston_output *output = NULL; struct weston_output *output = NULL;
if (output_resource != NULL) if (output_resource != NULL) {
output = weston_head_from_resource(output_resource)->output; struct weston_head *head =
weston_head_from_resource(output_resource);
if (head)
output = head->output;
}
weston_desktop_xdg_toplevel_ensure_added(toplevel); weston_desktop_xdg_toplevel_ensure_added(toplevel);
weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface, weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,