mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-15 08:14:28 +08:00
client: Fix reading long values
While value has more than single MTU can carry long read procedure will be triggered. In such cases offset need to bo considered while getting value from storage.
This commit is contained in:
parent
9786f58072
commit
1abee58711
@ -1412,6 +1412,39 @@ static const GDBusPropertyTable chrc_properties[] = {
|
||||
{ }
|
||||
};
|
||||
|
||||
static int parse_offset(DBusMessageIter *iter, uint16_t *offset)
|
||||
{
|
||||
DBusMessageIter dict;
|
||||
|
||||
if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
|
||||
return -EINVAL;
|
||||
|
||||
dbus_message_iter_recurse(iter, &dict);
|
||||
|
||||
while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
|
||||
const char *key;
|
||||
DBusMessageIter value, entry;
|
||||
int var;
|
||||
|
||||
dbus_message_iter_recurse(&dict, &entry);
|
||||
dbus_message_iter_get_basic(&entry, &key);
|
||||
|
||||
dbus_message_iter_next(&entry);
|
||||
dbus_message_iter_recurse(&entry, &value);
|
||||
|
||||
var = dbus_message_iter_get_arg_type(&value);
|
||||
if (strcasecmp(key, "offset") == 0) {
|
||||
if (var != DBUS_TYPE_UINT16)
|
||||
return -EINVAL;
|
||||
dbus_message_iter_get_basic(&value, offset);
|
||||
}
|
||||
|
||||
dbus_message_iter_next(&dict);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DBusMessage *read_value(DBusMessage *msg, uint8_t *value,
|
||||
uint16_t value_len)
|
||||
{
|
||||
@ -1433,8 +1466,14 @@ static DBusMessage *chrc_read_value(DBusConnection *conn, DBusMessage *msg,
|
||||
void *user_data)
|
||||
{
|
||||
struct chrc *chrc = user_data;
|
||||
DBusMessageIter iter;
|
||||
uint16_t offset = 0;
|
||||
|
||||
return read_value(msg, chrc->value, chrc->value_len);
|
||||
dbus_message_iter_init(msg, &iter);
|
||||
|
||||
parse_offset(&iter, &offset);
|
||||
|
||||
return read_value(msg, &chrc->value[offset], chrc->value_len - offset);
|
||||
}
|
||||
|
||||
static int parse_value_arg(DBusMessageIter *iter, uint8_t **value, int *len)
|
||||
@ -1785,8 +1824,14 @@ static DBusMessage *desc_read_value(DBusConnection *conn, DBusMessage *msg,
|
||||
void *user_data)
|
||||
{
|
||||
struct desc *desc = user_data;
|
||||
DBusMessageIter iter;
|
||||
uint16_t offset = 0;
|
||||
|
||||
return read_value(msg, desc->value, desc->value_len);
|
||||
dbus_message_iter_init(msg, &iter);
|
||||
|
||||
parse_offset(&iter, &offset);
|
||||
|
||||
return read_value(msg, &desc->value[offset], desc->value_len - offset);
|
||||
}
|
||||
|
||||
static DBusMessage *desc_write_value(DBusConnection *conn, DBusMessage *msg,
|
||||
|
Loading…
Reference in New Issue
Block a user