client/gatt: proxy_property_changed: check for NULL iterator
authorChristian Eggers <ceggers@arri.de>
Fri, 23 Sep 2022 14:58:12 +0000 (16:58 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
The passed iterator can be NULL as in
gdbus/client.c::properties_changed():
...
   proxy->prop_func(..., ..., iter=NULL, ...)
   +--client/gatt.c::proxy_property_changed(..., ..., iter, ...);
      +--dbus_message_iter_get_arg_type(iter);
...

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
client/gatt.c

index 3a08f05..0793ec9 100755 (executable)
@@ -3002,17 +3002,20 @@ static void proxy_property_changed(GDBusProxy *proxy, const char *name,
                        chrc->path, bt_uuidstr_to_str(chrc->uuid), name);
 
        if (!strcmp(name, "Value")) {
-               DBusMessageIter array;
-               uint8_t *value;
-               int len;
+               uint8_t *value = '\0';  /* don't pass NULL to write_value() */
+               int len = 0;
+
+               if (iter && dbus_message_iter_get_arg_type(iter) ==
+                               DBUS_TYPE_ARRAY) {
+                       DBusMessageIter array;
 
-               if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_ARRAY) {
                        dbus_message_iter_recurse(iter, &array);
                        dbus_message_iter_get_fixed_array(&array, &value, &len);
-                       write_value(&chrc->value_len, &chrc->value, value, len,
-                                       0, chrc->max_val_len);
-                       bt_shell_hexdump(value, len);
                }
+
+               write_value(&chrc->value_len, &chrc->value, value, len,
+                               0, chrc->max_val_len);
+               bt_shell_hexdump(value, len);
        }
 
        g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE, name);