From 73b95967b6d9a5f985b8e28ce9baacce6ace90e8 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 11 Jun 2024 08:41:45 +0900 Subject: [PATCH] e_keyrouter_wl: check if keygrab_set is available Check the mode, security and other conditions before keygab_set. Change-Id: I904df0afc679c9111db777599466796233b5ab8d --- src/bin/inputmgr/e_keyrouter_list.c | 32 -------------- src/bin/server/e_keyrouter_wl.c | 84 ++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/src/bin/inputmgr/e_keyrouter_list.c b/src/bin/inputmgr/e_keyrouter_list.c index fd92fa9..2719a01 100644 --- a/src/bin/inputmgr/e_keyrouter_list.c +++ b/src/bin/inputmgr/e_keyrouter_list.c @@ -15,13 +15,6 @@ e_keyrouter_set_keygrab_in_list(struct wl_resource *surface, struct wl_client *c { int res = TIZEN_KEYROUTER_ERROR_NONE; - EINA_SAFETY_ON_FALSE_RETURN_VAL - (((mode == TIZEN_KEYROUTER_MODE_EXCLUSIVE) || - (mode == TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE) || - (mode == TIZEN_KEYROUTER_MODE_TOPMOST) || - (mode == TIZEN_KEYROUTER_MODE_SHARED)), - TIZEN_KEYROUTER_ERROR_INVALID_MODE); - if (mode == TIZEN_KEYROUTER_MODE_EXCLUSIVE) { g_rec_mutex_lock(&krt->grab_key_mutex); @@ -33,12 +26,6 @@ e_keyrouter_set_keygrab_in_list(struct wl_resource *surface, struct wl_client *c g_rec_mutex_unlock(&krt->grab_key_mutex); } - if (mode == TIZEN_KEYROUTER_MODE_TOPMOST) - { - EINA_SAFETY_ON_NULL_RETURN_VAL - (surface, TIZEN_KEYROUTER_ERROR_INVALID_SURFACE); - } - res = e_keyrouter_prepend_to_keylist(surface, surface ? NULL : client, key, @@ -519,25 +506,6 @@ e_keyrouter_keygrab_set(struct wl_client *client, struct wl_resource *surface, i { int res=0; -#ifdef HAVE_CYNARA - if (EINA_FALSE == e_keyrouter_wl_util_do_privilege_check(client, mode, key)) - { - KLINF("No permission for %d grab mode ! (key=%d)", mode, key); - return TIZEN_KEYROUTER_ERROR_NO_PERMISSION; - } -#endif - - if (!surface) - { - /* Regarding topmost mode, a client must request to grab a key with a valid surface. */ - if (mode == TIZEN_KEYROUTER_MODE_TOPMOST) - { - KLWRN("Invalid surface for %d grab mode ! (key=%d)", mode, key); - - return TIZEN_KEYROUTER_ERROR_INVALID_SURFACE; - } - } - /* Check the given key range */ if (krt->max_tizen_hwkeys < key) { diff --git a/src/bin/server/e_keyrouter_wl.c b/src/bin/server/e_keyrouter_wl.c index 158faab..eb53c6a 100644 --- a/src/bin/server/e_keyrouter_wl.c +++ b/src/bin/server/e_keyrouter_wl.c @@ -233,29 +233,68 @@ _e_keyrouter_wl_array_length(const struct wl_array *array) return count; } +static int +_e_keyrouter_keygrab_set_available_check(struct wl_client *client, struct wl_resource *surface, int key, int mode) +{ + if (!((mode == TIZEN_KEYROUTER_MODE_EXCLUSIVE) || + (mode == TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE) || + (mode == TIZEN_KEYROUTER_MODE_TOPMOST) || + (mode == TIZEN_KEYROUTER_MODE_SHARED))) + return TIZEN_KEYROUTER_ERROR_INVALID_MODE; + +#ifdef HAVE_CYNARA + if (!e_keyrouter_wl_util_do_privilege_check(client, mode, key)) + { + KLINF("No permission for %d grab mode ! (key=%d)", mode, key); + return TIZEN_KEYROUTER_ERROR_NO_PERMISSION; + } +#endif + + /* Regarding topmost mode, a client must request to grab a key with a valid surface. */ + if (!surface && mode == TIZEN_KEYROUTER_MODE_TOPMOST) + { + KLWRN("Invalid surface for %d grab mode ! (key=%d)", mode, key); + return TIZEN_KEYROUTER_ERROR_INVALID_SURFACE; + } + + return TIZEN_KEYROUTER_ERROR_NONE; +} + static void _e_keyrouter_input_thread_keygrab_set(void *data) { - int res = 0; E_Input_Thread_Request_Keygrab_Data *keygrab_data = data; - EINA_SAFETY_ON_NULL_RETURN(keygrab_data); + int res = 0; - TRACE_INPUT_BEGIN(_e_keyrouter_cb_keygrab_set); + res = _e_keyrouter_keygrab_set_available_check(keygrab_data->client, + keygrab_data->surface, keygrab_data->key, keygrab_data->mode); + if (res != TIZEN_KEYROUTER_ERROR_NONE) + goto failed; - res = e_keyrouter_keygrab_set(keygrab_data->client, keygrab_data->surface, keygrab_data->key, keygrab_data->mode); + res = e_keyrouter_keygrab_set(keygrab_data->client, keygrab_data->surface, + keygrab_data->key, keygrab_data->mode); + if (res != TIZEN_KEYROUTER_ERROR_NONE) + goto failed; - TRACE_INPUT_END(); + KLINF("Success to %d key %s grab request (wl_client: %p, wl_surface: %p, pid: %d)", + keygrab_data->key, e_keyrouter_mode_to_string(keygrab_data->mode), + keygrab_data->client, keygrab_data->surface, + e_keyrouter_util_get_pid(keygrab_data->client, keygrab_data->surface)); - if (res == TIZEN_KEYROUTER_ERROR_NONE) - { - KLINF("Success to %d key %s grab request (wl_client: %p, wl_surface: %p, pid: %d)", keygrab_data->key, e_keyrouter_mode_to_string(keygrab_data->mode), - keygrab_data->client, keygrab_data->surface, e_keyrouter_util_get_pid(keygrab_data->client, keygrab_data->surface)); - } - else - KLINF("Failed to %d key %s grab request (wl_client: %p, wl_surface: %p, pid: %d): res: %d", keygrab_data->key, e_keyrouter_mode_to_string(keygrab_data->mode), - keygrab_data->client, keygrab_data->surface, e_keyrouter_util_get_pid(keygrab_data->client, keygrab_data->surface), res); + tizen_keyrouter_send_keygrab_notify(keygrab_data->resource, + keygrab_data->surface, keygrab_data->key, keygrab_data->mode, res); + + return; - tizen_keyrouter_send_keygrab_notify(keygrab_data->resource, keygrab_data->surface, keygrab_data->key, keygrab_data->mode, res); +failed: + KLINF("Failed to %d key %s grab request (wl_client: %p, wl_surface: %p, pid: %d): res: %d", + keygrab_data->key, e_keyrouter_mode_to_string(keygrab_data->mode), + keygrab_data->client, keygrab_data->surface, + e_keyrouter_util_get_pid(keygrab_data->client, keygrab_data->surface), + res); + + tizen_keyrouter_send_keygrab_notify(keygrab_data->resource, + keygrab_data->surface, keygrab_data->key, keygrab_data->mode, res); } /* tizen_keyrouter_set_keygrab request handler */ @@ -274,6 +313,8 @@ _e_keyrouter_cb_keygrab_set(struct wl_client *client, struct wl_resource *resour INF("client: %p, surface: %p, key: %d, mode: %d\n", keygrab_data.client, keygrab_data.surface, keygrab_data.key, keygrab_data.mode); _e_keyrouter_input_thread_keygrab_set(&keygrab_data); + + TRACE_INPUT_END(); } static void @@ -354,8 +395,17 @@ _e_keyrouter_cb_keygrab_set_list(struct wl_client *client, struct wl_resource *r wl_array_for_each(grab_request, grab_list) { - res = e_keyrouter_keygrab_set(client, surface, grab_request->key, grab_request->mode); + res = _e_keyrouter_keygrab_set_available_check(client, surface, + grab_request->key, grab_request->mode); + if (res != TIZEN_KEYROUTER_ERROR_NONE) + goto done; + + res = e_keyrouter_keygrab_set(client, surface, + grab_request->key, grab_request->mode); + +done: grab_request->err = res; + if (res == TIZEN_KEYROUTER_ERROR_NONE) KLDBG("Success to %d key %s grab using list(wl_client: %p, wl_surface: %p, pid: %d)", grab_request->key, e_keyrouter_mode_to_string(grab_request->mode), @@ -363,10 +413,12 @@ _e_keyrouter_cb_keygrab_set_list(struct wl_client *client, struct wl_resource *r else KLINF("Failed to %d key %s grab using list(wl_client: %p, wl_surface: %p, pid: %d): res: %d", grab_request->key, e_keyrouter_mode_to_string(grab_request->mode), - client, surface, e_keyrouter_util_get_pid(client, surface), grab_request->err); + client, surface, e_keyrouter_util_get_pid(client, surface), + grab_request->err); } TRACE_INPUT_END(); + tizen_keyrouter_send_keygrab_notify_list(resource, surface, grab_list); } -- 2.7.4