dbus: Avoid memcmp for string comparison
PATCH 1/2 dbus: Avoid memcmp for string comparison
As discussed in
https://lists.01.org/pipermail/ell/2018-August/001279.html gcc's Address Sanitizer may complain if we try using memcmp(A, B, len) to compare a null-terminated A shorter than len against a longer B so use strncmp instead.
--- ell/dbus-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ell/dbus-service.c +2 -2
@@ -1467,7 +1467,7 @@ bool _dbus_object_tree_add_interface(struct _dbus_object_tree *tree, manager = entry->data; path_len =strlen (manager->path); -if (memcmp (path, manager->path, path_len) || +if (strncmp (path, manager->path, path_len) || (path[path_len] !='\0' && path[path_len] !='/' && path_len >1 ))continue ;
@@ -1544,7 +1544,7 @@ bool _dbus_object_tree_remove_interface(struct _dbus_object_tree *tree, manager = entry->data; path_len =strlen (manager->path); -if (memcmp (path, manager->path, path_len) || +if (strncmp (path, manager->path, path_len) || (path[path_len] !='\0' && path[path_len] !='/' && path_len >1 ))continue ;
Signature · 1 line
2.14.1
PATCH 2/2 dbus: Emit InterfacesAdded on new ObjectManager addition
When an Object Manager interface is added to the tree emit InterfaceAdded signals for all the now-managed objects that may have existed already.
This way clients that register the Object Manager in the dbus ready callback will have no issues with InterfacesAdded signals missing if other interfaces have been registered and added before the callback.
--- ell/dbus-service.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
ell/dbus-service.c +43 -0
@@ -1410,6 +1410,43 @@ bool _dbus_object_tree_unregister_interface(struct _dbus_object_tree *tree,return true; } +static void collect_instances (struct object_node *node, +const char *path, +struct l_queue *announce) +{ +const struct l_queue_entry *entry; +struct interface_add_record *change_rec; +const struct child_node *child; + +if (!node->instances) + goto recurse; + + change_rec = l_new(struct interface_add_record, 1); + change_rec->path =l_strdup (path); + change_rec->object = node; + change_rec->instances =l_queue_new (); + +for (entry =l_queue_get_entries (node->instances); entry; + entry = entry->next) +l_queue_push_tail (change_rec->instances, entry->data); + +l_queue_push_tail (announce, change_rec); + +recurse: +if (!strcmp (path,"/" )) + path ="" ; + +for (child = node->children; child; child = child->next) { +char *child_path; + + child_path =l_strdup_printf ("%s/%s" , path, child->subpath); + +collect_instances (child->node, child_path, announce); + +l_free (child_path); + } +} +static bool match_interfaces_added_object (const void *a,const void *b) {const struct interface_add_record *rec = a;
@@ -1498,6 +1535,12 @@ bool _dbus_object_tree_add_interface(struct _dbus_object_tree *tree, manager->announce_removed =l_queue_new ();l_queue_push_tail (tree->object_managers, manager); + +/* Emit InterfacesAdded for interfaces added before OM */ +collect_instances (object, path, manager->announce_added); + +if (manager->dbus && !l_queue_isempty (manager->announce_added)) +schedule_emit_signals (manager->dbus); }return true;
Signature · 1 line
2.14.1
Hi Andrew,
Quoted 9 lines · Andrew Zaborowski
As discussed in
https://lists.01.org/pipermail/ell/2018-August/001279.html gcc's Address Sanitizer may complain if we try usingmemcmp(A, B, len)to compare a null-terminated A shorter than len against a longer B so use strncmp instead.--- ell/dbus-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Both applied, thanks.
Regards,
-Denis