Skip to content

Commit 8ba5b73

Browse files
Vudentzjhedberg
authored andcommitted
Bluetooth: GATT: Fix assuming writes to CCC will always contain 2 bytes
Although unlikely it is possible that a remote may attempt to send just 1 byte as the write request allows to do that: BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part F page 2320: 'If the attribute value has a fixed length and the Attribute Value parameter length is less than or equal to the length of the attribute value, the octets of the attribute value parameter length shall be written; all other octets in this attribute value shall be unchanged.' Fixes #16734 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 6e27d6d commit 8ba5b73

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,15 +1197,19 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
11971197
struct bt_gatt_ccc_cfg *cfg;
11981198
u16_t value;
11991199

1200-
if (offset > sizeof(u16_t)) {
1200+
if (offset) {
12011201
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
12021202
}
12031203

1204-
if (offset + len > sizeof(u16_t)) {
1204+
if (!len || len > sizeof(u16_t)) {
12051205
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
12061206
}
12071207

1208-
value = sys_get_le16(buf);
1208+
if (len < sizeof(u16_t)) {
1209+
value = *(u8_t *)buf;
1210+
} else {
1211+
value = sys_get_le16(buf);
1212+
}
12091213

12101214
cfg = find_ccc_cfg(conn, ccc);
12111215
if (!cfg) {

0 commit comments

Comments
 (0)