From 1e58e4006d72292ba890867f533731db75d63bcb Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Tue, 11 Jun 2024 11:37:41 +0300 Subject: [PATCH] xdg-popup: validate positioner on reposition request --- include/wlr/types/wlr_xdg_shell.h | 5 +++++ types/xdg_shell/wlr_xdg_popup.c | 18 ++++++++++-------- types/xdg_shell/wlr_xdg_positioner.c | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index e5b75c57..d54c5366 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -446,6 +446,11 @@ void wlr_xdg_popup_destroy(struct wlr_xdg_popup *popup); void wlr_xdg_popup_get_position(struct wlr_xdg_popup *popup, double *popup_sx, double *popup_sy); +/** + * Returns true if a positioner is complete. + */ +bool wlr_xdg_positioner_is_complete(struct wlr_xdg_positioner *positioner); + /** * Get the geometry based on positioner rules. */ diff --git a/types/xdg_shell/wlr_xdg_popup.c b/types/xdg_shell/wlr_xdg_popup.c index b2cc5b9d..082e06fb 100644 --- a/types/xdg_shell/wlr_xdg_popup.c +++ b/types/xdg_shell/wlr_xdg_popup.c @@ -317,8 +317,13 @@ static void xdg_popup_handle_reposition( return; } - struct wlr_xdg_positioner *positioner = - wlr_xdg_positioner_from_resource(positioner_resource); + struct wlr_xdg_positioner *positioner = wlr_xdg_positioner_from_resource(positioner_resource); + if (!wlr_xdg_positioner_is_complete(positioner)) { + wl_resource_post_error(popup->base->client->resource, + XDG_WM_BASE_ERROR_INVALID_POSITIONER, "positioner object is not complete"); + return; + } + wlr_xdg_positioner_rules_get_geometry( &positioner->rules, &popup->scheduled.geometry); popup->scheduled.rules = positioner->rules; @@ -365,14 +370,11 @@ static void xdg_popup_handle_resource_destroy(struct wl_resource *resource) { wlr_xdg_popup_destroy(popup); } -void create_xdg_popup(struct wlr_xdg_surface *surface, - struct wlr_xdg_surface *parent, +void create_xdg_popup(struct wlr_xdg_surface *surface, struct wlr_xdg_surface *parent, struct wlr_xdg_positioner *positioner, uint32_t id) { - if (positioner->rules.size.width == 0 || - positioner->rules.anchor_rect.width == 0) { + if (!wlr_xdg_positioner_is_complete(positioner)) { wl_resource_post_error(surface->client->resource, - XDG_WM_BASE_ERROR_INVALID_POSITIONER, - "positioner object is not complete"); + XDG_WM_BASE_ERROR_INVALID_POSITIONER, "positioner object is not complete"); return; } diff --git a/types/xdg_shell/wlr_xdg_positioner.c b/types/xdg_shell/wlr_xdg_positioner.c index 6a991bba..380c1131 100644 --- a/types/xdg_shell/wlr_xdg_positioner.c +++ b/types/xdg_shell/wlr_xdg_positioner.c @@ -203,6 +203,11 @@ static uint32_t xdg_positioner_gravity_to_wlr_edges( return xdg_positioner_anchor_to_wlr_edges((enum xdg_positioner_anchor)gravity); } +bool wlr_xdg_positioner_is_complete(struct wlr_xdg_positioner *positioner) { + struct wlr_xdg_positioner_rules *rules = &positioner->rules; + return rules->size.width > 0 && rules->anchor_rect.width > 0; +} + void wlr_xdg_positioner_rules_get_geometry( const struct wlr_xdg_positioner_rules *rules, struct wlr_box *box) { box->x = rules->offset.x;