Skip to content

Commit afcc4ef

Browse files
author
Kevin Moloney
committed
Fix Klocwork#2051,2060: Array may be outside index
* Added check to ensure _data_len is within index values. * Had to repeat the branch statement rather than move it because of memcpy. * Fixed bug introduced(c8ecd5f) in WString.h when "len" became protected. Signed-off-by: Kevin Moloney <kevin.moloney@emutex.com>
1 parent cacac37 commit afcc4ef

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

libraries/CurieBle/src/BleCharacteristic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ BleCharacteristic::_setValue(void)
165165
if (!_initialised)
166166
return BLE_STATUS_WRONG_STATE;
167167

168-
if (_data_len > _char_data.max_len)
168+
if ((_data_len > BLE_MAX_ATTR_DATA_LEN) && (_data_len > _char_data.max_len))
169169
return BLE_STATUS_NOT_ALLOWED;
170170

171171
status = ble_client_gatts_set_attribute_value(_handles.value_handle,
@@ -204,7 +204,7 @@ BleStatus
204204
BleCharacteristic::setValue(const String &str)
205205
{
206206
str.getBytes((unsigned char *)&_data, (unsigned int)_char_data.max_len, 0U);
207-
_data_len = str.len + 1;
207+
_data_len = str.length() + 1;
208208
return _setValue();
209209
}
210210

libraries/CurieBle/src/BleDescriptor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ BleDescriptor::_setValue(void)
7070
if (!_initialised)
7171
return BLE_STATUS_WRONG_STATE;
7272

73+
if (_desc.length > BLE_MAX_ATTR_DATA_LEN)
74+
return BLE_STATUS_NOT_ALLOWED;
75+
7376
return ble_client_gatts_set_attribute_value(_handle, _desc.length, _data, 0);
7477
}
7578

@@ -93,7 +96,7 @@ BleStatus
9396
BleDescriptor::setValue(const String &str)
9497
{
9598
str.getBytes((unsigned char *)&_data, (unsigned int)BLE_MAX_ATTR_DATA_LEN, 0U);
96-
_desc.length = str.len + 1;
99+
_desc.length = str.length() + 1;
97100
return _setValue();
98101
}
99102

0 commit comments

Comments
 (0)