ecore_evas:fix string comparison of device's identifier 39/271339/5
authorduna.oh <duna.oh@samsung.com>
Fri, 18 Feb 2022 04:30:06 +0000 (13:30 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Mon, 21 Feb 2022 09:10:48 +0000 (09:10 +0000)
Change-Id: I0ecfd04e021af8801dc5ae9c77bdc85a79cf0f0e

src/lib/ecore_input_evas/ecore_input_evas.c
src/lib/ecore_wl2/ecore_wl2_input.c
src/modules/ecore_evas/engines/tbm/ecore_evas_tbm.c
src/modules/ecore_evas/engines/wayland/ecore_evas_wayland_common.c

index 7858483..023cb36 100644 (file)
@@ -1014,6 +1014,7 @@ _ecore_event_evas_device_update(Evas *e, const char *name EINA_UNUSED, const cha
    Evas_Device *edev = NULL;
    char *edev_identifier;
 
+   if (!identifier) return;
    dev_list = evas_device_list(e, NULL);
    if (dev_list)
      {
@@ -1040,6 +1041,7 @@ ecore_event_evas_device_update(void *data EINA_UNUSED, int type, void *event)
 
    lookup = _ecore_event_window_match(e->window);
    if (!lookup) return ECORE_CALLBACK_PASS_ON;
+   if (!e->dev) return ECORE_CALLBACK_PASS_ON;
 
    if (type == ECORE_EVENT_DEVICE_SUBCLASS_UPDATE)
      {
index 0c19dae..057078d 100644 (file)
@@ -3376,6 +3376,7 @@ _ecore_wl2_input_device_info_broadcast(Ecore_Wl2_Tizen_Input_Device *dev, Eina_B
 
    if (!dev) return;
    if (!dev->name) return;
+   if (!dev->identifier) return;
    if (!dev->input || !dev->input->display) return;
 
    if (flag)
@@ -3414,6 +3415,7 @@ _ecore_wl2_input_devices_send(Ecore_Wl2_Input *input, Ecore_Wl2_Window *win)
 
    EINA_LIST_FOREACH(input->devmgr.devices, l, dev)
      {
+        if (!dev->name || !dev->identifier) continue;
         _ecore_wl2_input_device_info_send(win->id, dev->name, dev->identifier, dev->clas, dev->subclas, EINA_TRUE);
      }
 }
@@ -3519,7 +3521,11 @@ _ecore_wl2_input_device_manager_cb_device_add(void *data, struct tizen_input_dev
    Ecore_Wl2_Tizen_Input_Device *dev;
 
    if (!ewd) return;
-   if ((!identifier) || (!device) || (!seat)) return;
+   if ((!identifier) || (!device) || (!seat))
+     {
+        ERR("Invalid arguments. return");
+        return;
+     }
 
    input = wl_seat_get_user_data(seat);
 
@@ -3545,7 +3551,11 @@ _ecore_wl2_input_device_manager_cb_device_remove(void *data, struct tizen_input_
    Ecore_Wl2_Tizen_Input_Device *dev;
 
    if (!ewd) return;
-   if ((!identifier) || (!device) || (!seat)) return;
+   if ((!identifier) || (!device) || (!seat))
+     {
+        ERR("Invalid arguments. return");
+        return;
+     }
 
    input = wl_seat_get_user_data(seat);
 
index 4e44ef9..f441a0a 100644 (file)
@@ -171,6 +171,7 @@ _ecore_evas_tbm_cb_ecore_device_add(void *data, int type EINA_UNUSED, void *even
    ev = event;
 
    if (ee->prop.window != ev->window) return ECORE_CALLBACK_PASS_ON;
+   if (!ev->identifier) return ECORE_CALLBACK_PASS_ON;
    if (_ecore_evas_tbm_evas_device_find(ee->evas, ev->identifier, ev->clas)) return ECORE_CALLBACK_PASS_ON;
 
    seat = _ecore_evas_tbm_default_seat_get(ee->evas);
@@ -193,17 +194,23 @@ _ecore_evas_tbm_cb_ecore_device_del(void *data, int type EINA_UNUSED, void *even
    Eina_List *list, *l, *l_next;
    Evas_Device *device;
    const char *evas_device_description;
+   Evas_Device_Class evas_cls = EVAS_DEVICE_CLASS_NONE;
 
    ev = event;
 
    if (ee->prop.window != ev->window) return ECORE_CALLBACK_PASS_ON;
+   if (!ev->identifier) return ECORE_CALLBACK_PASS_ON;
+
+   evas_cls = _ecore_evas_tbm_ecore_device_class_to_evas(ev->clas);
 
    list = (Eina_List *)evas_device_list(ee->evas, NULL);
    EINA_LIST_FOREACH_SAFE(list, l, l_next, device)
      {
         evas_device_description = evas_device_description_get(device);
         if (!evas_device_description) continue;
-        if (!strncmp(evas_device_description, ev->identifier, strlen(ev->identifier)))
+
+        if (_ecore_evas_tbm_strcmp(evas_device_description, ev->identifier) &&
+            evas_device_class_get(device) == evas_cls)
           {
              evas_device_del(device);
           }
index 31ae764..de233e7 100644 (file)
@@ -1609,18 +1609,47 @@ _ecore_evas_wl_common_strcmp(const char *dst, const char *src)
 
 // TIZEN_ONLY(20171109): support a tizen_input_device_manager interface
 
+static Evas_Device_Class
+_ecore_evas_wl_common_ecore_device_class_to_evas(Ecore_Device_Class cls)
+{
+   switch (cls)
+     {
+        case ECORE_DEVICE_CLASS_NONE:
+          return EVAS_DEVICE_CLASS_NONE;
+        case ECORE_DEVICE_CLASS_SEAT:
+          return EVAS_DEVICE_CLASS_SEAT;
+        case ECORE_DEVICE_CLASS_KEYBOARD:
+          return EVAS_DEVICE_CLASS_KEYBOARD;
+        case ECORE_DEVICE_CLASS_MOUSE:
+          return EVAS_DEVICE_CLASS_MOUSE;
+        case ECORE_DEVICE_CLASS_TOUCH:
+          return EVAS_DEVICE_CLASS_TOUCH;
+        case ECORE_DEVICE_CLASS_PEN:
+          return EVAS_DEVICE_CLASS_PEN;
+        case ECORE_DEVICE_CLASS_WAND:
+          return EVAS_DEVICE_CLASS_WAND;
+        case ECORE_DEVICE_CLASS_GAMEPAD:
+          return EVAS_DEVICE_CLASS_GAMEPAD;
+        default:
+          return EVAS_DEVICE_CLASS_NONE;
+     }
+}
+
 static Eina_Bool
-_ecore_evas_wl_common_evas_device_find(Evas *evas, const char *name, const Evas_Device_Class clas, const char *identifier)
+_ecore_evas_wl_common_evas_device_find(Evas *evas, const char *name, const Ecore_Device_Class ecore_cls, const char *identifier)
 {
    Eina_List *list, *l;
    Evas_Device *device;
    const char *evas_device_name;
    const char *evas_device_description;
+   Evas_Device_Class evas_cls = EVAS_DEVICE_CLASS_NONE;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(evas, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(identifier, EINA_FALSE);
 
+   evas_cls = _ecore_evas_wl_common_ecore_device_class_to_evas(ecore_cls);
+
    list = (Eina_List *)evas_device_list(evas, NULL);
    EINA_LIST_FOREACH(list, l, device)
      {
@@ -1628,7 +1657,7 @@ _ecore_evas_wl_common_evas_device_find(Evas *evas, const char *name, const Evas_
         evas_device_description = evas_device_description_get(device);
         if (!evas_device_name || !evas_device_description) continue;
 
-        if ((evas_device_class_get(device) == clas) &&
+        if ((evas_device_class_get(device) == evas_cls) &&
             _ecore_evas_wl_common_strcmp(evas_device_name, name) &&
             _ecore_evas_wl_common_strcmp(evas_device_description, identifier))
           {
@@ -1672,6 +1701,8 @@ _ecore_evas_wl_common_cb_tizen_device_add(void *data EINA_UNUSED, int type EINA_
    Eina_List *l;
 
    ev = event;
+   if (!ev->name) return ECORE_CALLBACK_PASS_ON;
+   if (!ev->identifier) return ECORE_CALLBACK_PASS_ON;
    if (ev->window) win = ecore_wl2_window_find(ev->window);
    if (win) display = ecore_wl2_window_display_get(win);
 
@@ -1704,18 +1735,22 @@ _ecore_evas_wl_common_cb_tizen_device_del(void *data EINA_UNUSED, int type EINA_
    Ecore_Wl2_Display *display = NULL;
    Ecore_Evas *ee;
    Eina_List *list, *l, *ll, *ll_next;
+   const char *evas_device_name;
+   const char *evas_device_description;
+   Evas_Device_Class evas_cls = EVAS_DEVICE_CLASS_NONE;
 
    ev = event;
+   if (!ev->name) return ECORE_CALLBACK_PASS_ON;
+   if (!ev->identifier) return ECORE_CALLBACK_PASS_ON;
+   evas_cls = _ecore_evas_wl_common_ecore_device_class_to_evas(ev->clas);
+
    if (ev->window) win = ecore_wl2_window_find(ev->window);
    if (win) display = ecore_wl2_window_display_get(win);
 
-   if (!ev->identifier) return ECORE_CALLBACK_PASS_ON;
-
    EINA_LIST_FOREACH(ee_list, l, ee)
      {
         Ecore_Evas_Engine_Wl_Data *wdata;
         Evas_Device *device;
-        char *evas_device_description;
 
         wdata = ee->engine.data;
         if (display != wdata->display) continue;
@@ -1723,10 +1758,13 @@ _ecore_evas_wl_common_cb_tizen_device_del(void *data EINA_UNUSED, int type EINA_
         list = (Eina_List *)evas_device_list(ee->evas, NULL);
         EINA_LIST_FOREACH_SAFE(list, ll, ll_next, device)
           {
-             evas_device_description = (char *)evas_device_description_get(device);
-             if (!evas_device_description) continue;
+             evas_device_name = evas_device_name_get(device);
+             evas_device_description = evas_device_description_get(device);
+             if (!evas_device_name || !evas_device_description) continue;
 
-             if (_ecore_evas_wl_common_strcmp(evas_device_description, ev->identifier))
+             if ((evas_device_class_get(device) == evas_cls) &&
+                 _ecore_evas_wl_common_strcmp(evas_device_name, ev->name) &&
+                 _ecore_evas_wl_common_strcmp(evas_device_description, ev->identifier))
                {
                   evas_device_del(device);
                }