Skip to content

Commit 29e8546

Browse files
committed
bluetooth: services: ras: Fix unaligned memory access in RAS
Running tests with UBSAN identified unaligned memory access of the ranging counter. Fix this by using net_buf_simple. Signed-off-by: Sean Madigan <[email protected]>
1 parent a0fa602 commit 29e8546

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

subsys/bluetooth/services/ras/rreq/ras_rreq.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ static uint8_t ranging_data_ready_notify_func(struct bt_conn *conn,
143143
return BT_GATT_ITER_STOP;
144144
}
145145

146-
uint16_t ranging_counter = *(uint16_t *)data;
146+
struct net_buf_simple rd_ready;
147+
148+
net_buf_simple_init_with_data(&rd_ready, (uint8_t *)data, length);
149+
uint16_t ranging_counter = net_buf_simple_pull_le16(&rd_ready);
147150

148151
if (rreq->rd_ready.cb) {
149152
rreq->rd_ready.cb(conn, ranging_counter);
@@ -187,7 +190,10 @@ static uint8_t ranging_data_overwritten_notify_func(struct bt_conn *conn,
187190
return BT_GATT_ITER_STOP;
188191
}
189192

190-
uint16_t ranging_counter = *(uint16_t *)data;
193+
struct net_buf_simple rd_overwritten;
194+
195+
net_buf_simple_init_with_data(&rd_overwritten, (uint8_t *)data, length);
196+
uint16_t ranging_counter = net_buf_simple_pull_le16(&rd_overwritten);
191197

192198
if (rreq->on_demand_rd.data_get_in_progress &&
193199
rreq->on_demand_rd.counter_in_progress == ranging_counter) {

0 commit comments

Comments
 (0)