Skip to content

Commit 2b2a56c

Browse files
committed
[Bugfix] Clear attribute value when zero length value is written.
1 parent bdeb084 commit 2b2a56c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/NimBLEAttValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void NimBLEAttValue::deepCopy(const NimBLEAttValue& source) {
105105

106106
// Set the value of the attribute.
107107
bool NimBLEAttValue::setValue(const uint8_t* value, uint16_t len) {
108-
m_attr_len = 0; // Just set the value length to 0 and append instead of repeating code.
108+
m_attr_len = 0; // Just set the value length to 0 and append instead of repeating code.
109+
m_attr_value[0] = '\0'; // Set the first byte to 0 incase the len of the new value is 0.
109110
append(value, len);
110111
return memcmp(m_attr_value, value, len) == 0 && m_attr_len == len;
111112
}

src/NimBLEServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,12 @@ int NimBLEServer::handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_
635635
case BLE_GATT_ACCESS_OP_WRITE_DSC:
636636
case BLE_GATT_ACCESS_OP_WRITE_CHR: {
637637
uint16_t maxLen = val.max_size();
638-
if (ctxt->om->om_len > maxLen) {
638+
uint16_t len = ctxt->om->om_len;
639+
if (len > maxLen) {
639640
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
640641
}
641642

642-
uint8_t buf[maxLen];
643-
uint16_t len = ctxt->om->om_len;
643+
uint8_t buf[maxLen];
644644
memcpy(buf, ctxt->om->om_data, len);
645645

646646
os_mbuf* next;

0 commit comments

Comments
 (0)