chiark / gitweb /
sd-bus: fix parsing of KDBUS_CMD_LIST
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 30 Jul 2015 12:12:09 +0000 (14:12 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:07:20 +0000 (10:07 +0100)
We *must not* assume that an entry returned by KDBUS_CMD_LIST only
carries a single KDBUS_ITEM_OWNED_NAME. Similarly, we already parse
multiple such items for message-metadata, so make sure we support the
same on KDBUS_CMD_LIST.

By relying on the kernel to return all names separately, we limit the
kernel API significantly. Stop this and let the kernel decide how to
return its data.

src/libelogind/sd-bus/bus-control.c

index 99115d5e492f4157ee3722bc51a4e60131d63b8a..4c45a58e8b609221339024736329b803a43964f6 100644 (file)
@@ -256,9 +256,7 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
         name_list = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd.offset);
 
         KDBUS_FOREACH(name, name_list, cmd.list_size) {
-
                 struct kdbus_item *item;
-                const char *entry_name = NULL;
 
                 if ((flags & KDBUS_LIST_UNIQUE) && name->id != previous_id) {
                         char *n;
@@ -275,15 +273,15 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
                         previous_id = name->id;
                 }
 
-                KDBUS_ITEM_FOREACH(item, name, items)
-                        if (item->type == KDBUS_ITEM_OWNED_NAME)
-                                entry_name = item->name.name;
-
-                if (entry_name && service_name_is_valid(entry_name)) {
-                        r = strv_extend(x, entry_name);
-                        if (r < 0) {
-                                r = -ENOMEM;
-                                goto fail;
+                KDBUS_ITEM_FOREACH(item, name, items) {
+                        if (item->type == KDBUS_ITEM_OWNED_NAME) {
+                                if (service_name_is_valid(item->name.name)) {
+                                        r = strv_extend(x, item->name.name);
+                                        if (r < 0) {
+                                                r = -ENOMEM;
+                                                goto fail;
+                                        }
+                                }
                         }
                 }
         }