xdg-popup: validate positioner on reposition request

master
Kirill Primak 5 months ago
parent e7deea44fd
commit 1e58e4006d

@ -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, void wlr_xdg_popup_get_position(struct wlr_xdg_popup *popup,
double *popup_sx, double *popup_sy); 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. * Get the geometry based on positioner rules.
*/ */

@ -317,8 +317,13 @@ static void xdg_popup_handle_reposition(
return; return;
} }
struct wlr_xdg_positioner *positioner = struct wlr_xdg_positioner *positioner = wlr_xdg_positioner_from_resource(positioner_resource);
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( wlr_xdg_positioner_rules_get_geometry(
&positioner->rules, &popup->scheduled.geometry); &positioner->rules, &popup->scheduled.geometry);
popup->scheduled.rules = positioner->rules; 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); wlr_xdg_popup_destroy(popup);
} }
void create_xdg_popup(struct wlr_xdg_surface *surface, void create_xdg_popup(struct wlr_xdg_surface *surface, struct wlr_xdg_surface *parent,
struct wlr_xdg_surface *parent,
struct wlr_xdg_positioner *positioner, uint32_t id) { struct wlr_xdg_positioner *positioner, uint32_t id) {
if (positioner->rules.size.width == 0 || if (!wlr_xdg_positioner_is_complete(positioner)) {
positioner->rules.anchor_rect.width == 0) {
wl_resource_post_error(surface->client->resource, wl_resource_post_error(surface->client->resource,
XDG_WM_BASE_ERROR_INVALID_POSITIONER, XDG_WM_BASE_ERROR_INVALID_POSITIONER, "positioner object is not complete");
"positioner object is not complete");
return; return;
} }

@ -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); 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( void wlr_xdg_positioner_rules_get_geometry(
const struct wlr_xdg_positioner_rules *rules, struct wlr_box *box) { const struct wlr_xdg_positioner_rules *rules, struct wlr_box *box) {
box->x = rules->offset.x; box->x = rules->offset.x;

Loading…
Cancel
Save