From 2e667118aeff192f2bafa38927748bee0814a96b Mon Sep 17 00:00:00 2001 From: fabik111 Date: Thu, 3 Oct 2024 14:52:10 +0200 Subject: [PATCH] fix crashes on M0 board when assigning the BLE handle from the received data buffer --- src/utility/ATT.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index b1796c90..9367cfbf 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -993,8 +993,8 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_ } /// if auth error, hold the response in a buffer. bool holdResponse = false; - - uint16_t handle = *(uint16_t*)data; + uint16_t handle; + memcpy(&handle, data, sizeof(handle)); uint16_t offset = (opcode == ATT_OP_READ_REQ) ? 0 : *(uint16_t*)&data[sizeof(handle)]; if ((uint16_t)(handle - 1) > GATT.attributeCount()) { @@ -1248,7 +1248,8 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op return; } - uint16_t handle = *(uint16_t*)data; + uint16_t handle; + memcpy(&handle, data, sizeof(handle)); if ((uint16_t)(handle - 1) > GATT.attributeCount()) { if (withResponse) {