Skip to content

Commit

Permalink
apps/bttester: fix get_attrs response buffer
Browse files Browse the repository at this point in the history
Assigning rsp pointer to new value caused wrong behavior and corrupted
response. Data should be copied into buffer instead.
  • Loading branch information
KKopyscinski authored and sjanc committed Jul 27, 2023
1 parent 65f32e5 commit c8743c6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions apps/bttester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,10 @@ get_attrs(const void *cmd, uint16_t cmd_len,

SYS_LOG_DBG("");

if (!buf) {
return BTP_STATUS_FAILED;
}

memset(str, 0, sizeof(str));
memset(&uuid, 0, sizeof(uuid));
start_handle = le16toh(cp->start_handle);
Expand All @@ -1712,7 +1716,7 @@ get_attrs(const void *cmd, uint16_t cmd_len,
if (cp->type_length) {
if (btp2bt_uuid(cp->type, cp->type_length, &uuid)) {
status = BTP_STATUS_FAILED;
goto free;
goto done;
}

ble_uuid_to_str(&uuid.u, str);
Expand All @@ -1724,12 +1728,6 @@ get_attrs(const void *cmd, uint16_t cmd_len,
SYS_LOG_DBG("start 0x%04x end 0x%04x", start_handle, end_handle);
}

rp = os_mbuf_extend(buf, sizeof(*rp));
if (!rp) {
status = BTP_STATUS_FAILED;
goto free;
}

entry = ble_att_svr_find_by_uuid(entry, uuid_ptr, end_handle);
while (entry) {

Expand All @@ -1742,7 +1740,7 @@ get_attrs(const void *cmd, uint16_t cmd_len,
gatt_attr = os_mbuf_extend(buf, sizeof(*gatt_attr));
if (!gatt_attr) {
status = BTP_STATUS_FAILED;
goto free;
goto done;
}
gatt_attr->handle = htole16(entry->ha_handle_id);
gatt_attr->permission = flags_hs2btp(entry->ha_flags);
Expand All @@ -1765,10 +1763,11 @@ get_attrs(const void *cmd, uint16_t cmd_len,
}

rp->attrs_count = count;
memcpy(rp->attrs, buf->om_data, buf->om_len);

*rsp_len = sizeof(*rp) + buf->om_len;

free:
done:
os_mbuf_free_chain(buf);
return status;
}
Expand Down

0 comments on commit c8743c6

Please sign in to comment.