From 8ed2d03ef3cff2265decdb43c4fc574158ae837f Mon Sep 17 00:00:00 2001 From: Maria Bialota Date: Thu, 19 Mar 2020 19:04:50 +0100 Subject: [PATCH] [Elm AT-SPI Bridge] Replaced service name validation with sanitization. This is to enable proper handling of services with names containing non-standard characters such as @. Change-Id: Iff2ee845648c6e40fd9c950e7fb02ea331cff818 --- src/lib/elementary/elm_atspi_bridge.c | 49 ++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/lib/elementary/elm_atspi_bridge.c b/src/lib/elementary/elm_atspi_bridge.c index 139e02d..217b4c2 100644 --- a/src/lib/elementary/elm_atspi_bridge.c +++ b/src/lib/elementary/elm_atspi_bridge.c @@ -7236,33 +7236,36 @@ EAPI void elm_atspi_bridge_utils_proxy_connect(Eo *proxy) _plug_connect(pd->a11y_bus, proxy); } -//TIZEN_ONLY(20180810) atspi: check service, bus and path names for Dbus communication +//TIZEN_ONLY(20200320) atspi: sanitize service, bus and path names for Dbus communication /** * @brief In according to following specification: * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path + * We prepare service name to not contain any irregular characters such as @. + * The function below perform preliminary service name sanitization, + * then _sanitize_bus_name() and _sanitize_path_name() are performed accordingly. */ -static Eina_Bool _check_service_name(const char *str) +static char *_sanitize_service_name(const char *str) { - if (!str) - return EINA_FALSE; + char *res = eina_strdup(str); + if(!res) + return NULL; - char *tmp = (char *)str; + char *tmp = res; while (*tmp) { if (!isalnum(*tmp) && *tmp != '_' && *tmp != '-' && *tmp != '.') { - ERR("Invalid service name: %s, following character is forbidden in Dbus specification: %c", str, *tmp); - return EINA_FALSE; + *tmp = '_'; } ++tmp; } - return EINA_TRUE; + return res; } static char *_sanitize_bus_name(const char *str) { - char *res = strdup(str); + char *res = eina_strdup(str); if(!res) return NULL; char *tmp = res; @@ -7282,7 +7285,7 @@ static char *_sanitize_bus_name(const char *str) static char *_sanitize_path_name(const char *str) { - char *res = strdup(str); + char *res = eina_strdup(str); if(!res) return NULL; char *tmp = res; @@ -7296,40 +7299,49 @@ static char *_sanitize_path_name(const char *str) return res; } -// Eo* _elm_atspi_bridge_utils_proxy_create(Eo *parent, const char *svcname, int svcnum, Elm_Atspi_Proxy_Type type) { Eo *ret; - //TIZEN_ONLY(20180810) atspi: check service, bus and path names for Dbus communication + char bus[256], path[256]; int res; - Eina_Bool c = _check_service_name(svcname); - if (!c) return NULL; + char *svc_sanitized = _sanitize_service_name(svcname); + if (!svc_sanitized) + { + return NULL; + } - res = snprintf(bus, sizeof(bus), "elm.atspi.proxy.socket-%s-%d", svcname, svcnum); + res = snprintf(bus, sizeof(bus), "elm.atspi.proxy.socket-%s-%d", svc_sanitized, svcnum); if (res < 0 || (res >= (int)sizeof(bus))) { ERR("Error occured during creating bus name"); + free(svc_sanitized); return NULL; } - res = snprintf(path, sizeof(path), "/elm/atspi/proxy/socket/%s/%d", svcname, svcnum); + res = snprintf(path, sizeof(path), "/elm/atspi/proxy/socket/%s/%d", svc_sanitized, svcnum); if (res < 0 || (res >= (int)sizeof(path))) { ERR("Error occured during creating bus name"); + free(svc_sanitized); return NULL; } ret = efl_add(ELM_ATSPI_PROXY_CLASS, parent, elm_obj_atspi_proxy_ctor(efl_added, type)); - if (!ret) return NULL; + if (!ret) + { + free(svc_sanitized); + return NULL; + } char *bus_sanitized = _sanitize_bus_name(bus); char *path_sanitized = _sanitize_path_name(path); if(!bus_sanitized || !path_sanitized) { + free(svc_sanitized); free(bus_sanitized); free(path_sanitized); return NULL; @@ -7341,16 +7353,17 @@ Eo* _elm_atspi_bridge_utils_proxy_create(Eo *parent, const char *svcname, int sv _bridge_object_register(_instance, ret); _bridge_object_register(_instance, parent); } - // efl_key_data_set(ret, "__svc_bus", eina_stringshare_add(bus_sanitized)); efl_key_data_set(ret, "__svc_path", eina_stringshare_add(path_sanitized)); + free(svc_sanitized); free(bus_sanitized); free(path_sanitized); return ret; } +// static void _on_socket_del(void *data, const Efl_Event *event) -- 2.7.4