subsurface: Raise a protocol error about wl_subsurface.place_(above/below). 32/246932/3
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 22 Sep 2020 02:59:22 +0000 (11:59 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Mon, 9 Nov 2020 02:49:38 +0000 (11:49 +0900)
Check for bad sibling and raise the required error.

Change-Id: Iaa2af9818e35c62fbc8b15ed5222c4bc431eba2a

src/bin/e_comp_wl_subsurface.c

index 5c8d6bf0e215aa27c258d446deb2e7e0680d9cdb..3c4b05d986986c366316b88c1d8eaffd4e935e56 100644 (file)
@@ -542,6 +542,29 @@ _e_comp_wl_subsurface_cb_position_set(struct wl_client *client EINA_UNUSED, stru
    sdata->position.set = EINA_TRUE;
 }
 
+static Eina_Bool
+_subsurface_sibling_check(E_Client *ec1, E_Client *ec2)
+{
+   E_Client *parent, *sibling;
+   Eina_List *l;
+
+   parent = ec1->comp_data->sub.data->parent;
+
+   EINA_LIST_FOREACH(parent->comp_data->sub.list_pending, l, sibling)
+     {
+        if ((sibling != ec1) && (sibling == ec2))
+          return EINA_TRUE;
+     }
+
+   EINA_LIST_FOREACH(parent->comp_data->sub.below_list_pending, l, sibling)
+     {
+        if ((sibling != ec1) && (sibling == ec2))
+          return EINA_TRUE;
+     }
+
+   return EINA_FALSE;
+}
+
 static void
 _e_comp_wl_subsurface_cb_place_above(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *sibling_resource)
 {
@@ -563,6 +586,15 @@ _e_comp_wl_subsurface_cb_place_above(struct wl_client *client EINA_UNUSED, struc
    if (!(parent = ec->comp_data->sub.data->parent)) return;
    if (e_object_is_del(E_OBJECT(parent)) || !parent->comp_data) return;
 
+   if (!_subsurface_sibling_check(ec, ecs))
+     {
+        wl_resource_post_error(ec->comp_data->sub.data->resource,
+                               WL_SUBSURFACE_ERROR_BAD_SURFACE,
+                               "%s: wl_surface@%d is not a parent or sibling",
+                               "place_above", wl_resource_get_id(ecs->comp_data->surface));
+        return;
+     }
+
    parent->comp_data->sub.list_pending =
      eina_list_remove(parent->comp_data->sub.list_pending, ec);
 
@@ -593,6 +625,15 @@ _e_comp_wl_subsurface_cb_place_below(struct wl_client *client EINA_UNUSED, struc
    if (!(parent = ec->comp_data->sub.data->parent)) return;
    if (e_object_is_del(E_OBJECT(parent)) || !parent->comp_data) return;
 
+   if (!_subsurface_sibling_check(ec, ecs))
+     {
+        wl_resource_post_error(ec->comp_data->sub.data->resource,
+                               WL_SUBSURFACE_ERROR_BAD_SURFACE,
+                               "%s: wl_surface@%d is not a parent or sibling",
+                               "place_below", wl_resource_get_id(ecs->comp_data->surface));
+        return;
+     }
+
    parent->comp_data->sub.list_pending =
      eina_list_remove(parent->comp_data->sub.list_pending, ec);