Skip to content

Commit

Permalink
[Silabs]Add a static assert to ensure there is no out of bound write (#…
Browse files Browse the repository at this point in the history
…31268)

* Add a static assert to ensure there is no out of bound write

* address comments
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Jan 8, 2024
1 parent 6edaaa4 commit 4364474
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
static BLEManagerImpl sInstance;

// ===== Private members reserved for use by this class only.

enum class Flags : uint16_t
{
kAdvertisingEnabled = 0x0001,
Expand All @@ -161,6 +160,10 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
kUnusedIndex = 0xFF,
};

static constexpr uint8_t kFlagTlvSize = 3; // 1 byte for length, 1b for type and 1b for the Flag value
static constexpr uint8_t kUUIDTlvSize = 4; // 1 byte for length, 1b for type and 2b for the UUID value
static constexpr uint8_t kDeviceNameTlvSize = (2 + kMaxDeviceNameLength); // 1 byte for length, 1b for type and + device name

struct CHIPoBLEConState
{
#if !(SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
Expand Down
1 change: 1 addition & 0 deletions src/platform/silabs/efr32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)

mDeviceNameLength = strlen(mDeviceName); // Device Name length + length field
VerifyOrExit(mDeviceNameLength < kMaxDeviceNameLength, err = CHIP_ERROR_INVALID_ARGUMENT);
static_assert((kUUIDTlvSize + kDeviceNameTlvSize) <= MAX_RESPONSE_DATA_LEN, "Scan Response buffer is too small");

mDeviceIdInfoLength = sizeof(mDeviceIdInfo); // Servicedatalen + length+ UUID (Short)
static_assert(sizeof(mDeviceIdInfo) + CHIP_ADV_SHORT_UUID_LEN + 1 <= UINT8_MAX, "Our length won't fit in a uint8_t");
Expand Down
1 change: 1 addition & 0 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)

mDeviceNameLength = strlen(mDeviceName); // Device Name length + length field
VerifyOrExit(mDeviceNameLength < kMaxDeviceNameLength, err = CHIP_ERROR_INVALID_ARGUMENT);
static_assert((kFlagTlvSize + kUUIDTlvSize + kDeviceNameTlvSize) <= MAX_RESPONSE_DATA_LEN, "Scan Response buffer is too small");

mDeviceIdInfoLength = sizeof(mDeviceIdInfo); // Servicedatalen + length+ UUID (Short)
static_assert(sizeof(mDeviceIdInfo) + CHIP_ADV_SHORT_UUID_LEN + 1 <= UINT8_MAX, "Our length won't fit in a uint8_t");
Expand Down

0 comments on commit 4364474

Please sign in to comment.