Skip to content

Commit 17bf709

Browse files
ignore offset, replace whole value of attr in auth callback
1 parent 55ffb17 commit 17bf709

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

connectivity/FEATURE_BLE/include/ble/gatt/GattCharacteristic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,10 @@ class GattCharacteristic {
16921692
* @note The params->len parameter initially contains the maximum length of
16931693
* data that can be returned. Set it to the length of your data but it must
16941694
* not be larger than the original value.
1695+
*
1696+
* @note You must also take into account the offset provided in params->offset.
1697+
* The params->len you provide must be larger then the offset as the read operation
1698+
* will attempt to read at that offset.
16951699
*/
16961700
GattAuthCallbackReply_t authorizeRead(GattReadAuthCallbackParams *params)
16971701
{

connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,9 @@ uint8_t GattServer::atts_read_cb(
11481148

11491149
/* if new data provided copy into the attribute value buffer */
11501150
if (read_auth_params.data) {
1151-
if (read_auth_params.offset + read_auth_params.len > pAttr->maxLen) {
1152-
tr_error("Read authorisation callback set length larger than maximum attribute length. Cannot copy data");
1151+
if (read_auth_params.len > pAttr->maxLen || offset >= read_auth_params.len) {
1152+
tr_error("Read authorisation callback set length larger than maximum attribute length "
1153+
"or current offset is beyond new length. Cannot copy data");
11531154

11541155
GattReadCallbackParams read_params = {
11551156
connId,
@@ -1164,7 +1165,7 @@ uint8_t GattServer::atts_read_cb(
11641165
return ATT_ERR_UNLIKELY;
11651166
}
11661167

1167-
memcpy(pAttr->pValue + read_auth_params.offset, read_auth_params.data, read_auth_params.len);
1168+
memcpy(pAttr->pValue, read_auth_params.data, read_auth_params.len);
11681169
*pAttr->pLen = read_auth_params.len;
11691170
}
11701171
}

0 commit comments

Comments
 (0)