Skip to content

Commit a9550cf

Browse files
committed
Saturate length of retrieved advertisement data
1 parent 55d5bf2 commit a9550cf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/BLEDevice.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ String BLEDevice::advertisedServiceUuid(int index) const
184184
return serviceUuid;
185185
}
186186

187-
int BLEDevice::advertisementData(uint8_t value[], int length)
187+
int BLEDevice::advertisementData(uint8_t value[], int length) const
188188
{
189-
if (_eirDataLength > length) return 0; // Check that buffer size is sufficient
189+
if (length > _eirDataLength) length = _eirDataLength;
190190

191-
if (_eirDataLength) {
192-
memcpy(value, _eirData, _eirDataLength);
191+
if (length) {
192+
memcpy(value, _eirData, length);
193193
}
194194

195-
return _eirDataLength;
195+
return length;
196196
}
197197

198198
int BLEDevice::rssi()

src/BLEDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BLEDevice {
5959
String advertisedServiceUuid() const;
6060
String advertisedServiceUuid(int index) const;
6161

62-
int advertisementData(uint8_t value[], int length);
62+
int advertisementData(uint8_t value[], int length) const;
6363

6464
virtual int rssi();
6565

0 commit comments

Comments
 (0)