Fix invalid memory access 59/245959/2 accepted/tizen/unified/20201028.123905 submit/tizen/20201027.091012
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Tue, 20 Oct 2020 13:28:42 +0000 (15:28 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Tue, 20 Oct 2020 14:27:30 +0000 (16:27 +0200)
Change-Id: I36ca4b0ac8772ba9b7e34d60449971e0b681ceda

atspi/atspi-accessible.c

index 394913c..2cc4cb4 100644 (file)
@@ -2410,12 +2410,41 @@ atspi_accessible_get_accessible_id (AtspiAccessible *obj, GError **error)
 gboolean
 atspi_accessible_is_equal (AtspiAccessible *obj, AtspiAccessible *other)
 {
+  static const char prefix[] = "/org/a11y/atspi/accessible/";
+  static const size_t prefix_len = sizeof(prefix)/sizeof(char);
+
   if (obj == other)
     return TRUE;
   if (!obj || !other)
     return FALSE;
-  return !g_strcmp0(obj->parent.app->bus_name, other->parent.app->bus_name) &&
-         !g_strcmp0(obj->parent.path, other->parent.path);
+
+  /*
+   * Is it possible to have 2 different objects representing
+   * the same application? If not we should compare only pointers
+   * (obj->parent.app and other->parent.app)
+   */
+
+  /* One of them is null  */
+  if ((obj->parent.app != other->parent.app) && (!obj->parent.app || !other->parent.app))
+      return FALSE;
+
+  /* Both are not null */
+  if ((obj->parent.app != other->parent.app) && g_strcmp0(obj->parent.app->bus_name, other->parent.app->bus_name))
+      return FALSE;
+
+  const AtspiObject *o1 = ATSPI_OBJECT (obj);
+  const AtspiObject *o2 = ATSPI_OBJECT (other);
+
+  const char *path1 = o1 ? o1->path : "";
+  const char *path2 = o2 ? o2->path : "";
+
+  if (!strncmp(path1, prefix, prefix_len))
+      path1 += prefix_len;
+
+  if (!strncmp(path2, prefix, prefix_len))
+      path2 += prefix_len;
+
+  return !g_strcmp0(path1, path2);
 }
 
 void