gatt: Accept empty array in parse_includes()
authorJie Jiang <jiejiang@chromium.org>
Wed, 26 Aug 2020 06:37:42 +0000 (23:37 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:50 +0000 (14:30 +0530)
Currently parse_includes() will return false if the "Includes" property
is an empty array. Empty array in the "Includes" property should be
treated as valid.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/gatt-database.c

index 14c1ce8..a6b9dbc 100644 (file)
@@ -2408,6 +2408,7 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
        DBusMessageIter iter;
        DBusMessageIter array;
        char *obj;
+       int type;
 
        /* Includes property is optional */
        if (!g_dbus_proxy_get_property(proxy, "Includes", &iter))
@@ -2418,9 +2419,9 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
 
        dbus_message_iter_recurse(&iter, &array);
 
-       do {
-               if (dbus_message_iter_get_arg_type(&array) !=
-                                               DBUS_TYPE_OBJECT_PATH)
+       while ((type = dbus_message_iter_get_arg_type(&array))
+                                       != DBUS_TYPE_INVALID) {
+               if (type != DBUS_TYPE_OBJECT_PATH)
                        return false;
 
                dbus_message_iter_get_basic(&array, &obj);
@@ -2428,11 +2429,12 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
                if (!queue_push_tail(service->includes, obj)) {
                        error("Failed to add Includes path in queue\n");
                        return false;
-
                }
 
                incr_attr_count(service, 1);
-       } while (dbus_message_iter_next(&array));
+
+               dbus_message_iter_next(&array);
+       }
 
        return true;
 }