From: Alejandro PiƱeiro Date: Mon, 9 Dec 2013 17:08:20 +0000 (+0100) Subject: role: add some checks on atk_role_register for wrong role names X-Git-Tag: ATK_2_11_4~28 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eacee483828a5f77e8bd80ae68edbf077549aa9e;p=platform%2Fupstream%2Fatk.git role: add some checks on atk_role_register for wrong role names Related with downstream bug: https://bugzilla.redhat.com/show_bug.cgi?id=983891 --- diff --git a/atk/atkobject.c b/atk/atkobject.c index 1848fb3..72cfbdd 100755 --- a/atk/atkobject.c +++ b/atk/atkobject.c @@ -896,13 +896,29 @@ atk_object_ref_relation_set (AtkObject *accessible) * atk_role_register: * @name: a character string describing the new role. * - * Registers the role specified by @name. + * Registers the role specified by @name. @name must be a meaningful + * name. So it should not be empty, or consisting on whitespaces. * - * Returns: an #AtkRole for the new role. + * Returns: an #AtkRole for the new role if added + * properly. ATK_ROLE_INVALID in case of error. **/ AtkRole atk_role_register (const gchar *name) { + gboolean valid = FALSE; + gint i = 0; + glong length = g_utf8_strlen (name, -1); + + for (i=0; i < length; i++) { + if (name[i]!=' ') { + valid = TRUE; + break; + } + } + + if (!valid) + return ATK_ROLE_INVALID; + if (!role_names) initialize_role_names (); diff --git a/tests/testrole.c b/tests/testrole.c index 593549e..2f5bacc 100644 --- a/tests/testrole.c +++ b/tests/testrole.c @@ -80,6 +80,23 @@ test_role (void) g_print ("Unexpected name for undefined role %s\n", name); result = FALSE; } + + role1 = atk_role_register (""); + if (role1 != ATK_ROLE_INVALID) + { + g_print ("atk_role_register allowed to register empty string, but this is " + "an invalid role name\n"); + result = FALSE; + } + + role1 = atk_role_register (" "); + if (role1 != ATK_ROLE_INVALID) + { + g_print ("atk_role_register allowed to register all whitespace string, but " + "that is an invalid role name \n"); + result = FALSE; + } + return result; }