[atk] role: add some checks on atk_role_register for wrong role names



commit eacee483828a5f77e8bd80ae68edbf077549aa9e
Author: Alejandro Piñeiro <apinheiro igalia com>
Date:   Mon Dec 9 18:08:20 2013 +0100

    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

 atk/atkobject.c  |   20 ++++++++++++++++++--
 tests/testrole.c |   17 +++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
---
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;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]