Skip to content

Commit 9571dbe

Browse files
fix: validate dynamic endpoint index in bridge sample
Reject invalid indices and null device entries to prevent a null-pointer dereference while handling attribute reads. Signed-off-by: Dominik Michalczyk <dominik.michalczyk@nordicsemi.no>
1 parent 2abed78 commit 9571dbe

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎samples/bridge/src/core/bridge_manager.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,13 @@ CHIP_ERROR BridgeManager::HandleRead(uint16_t index, ClusterId clusterId,
381381
uint16_t maxReadLength)
382382
{
383383
VerifyOrReturnError(attributeMetadata && buffer, CHIP_ERROR_INVALID_ARGUMENT);
384+
VerifyOrReturnError(index != kEmberInvalidEndpointIndex, CHIP_ERROR_INVALID_ARGUMENT);
384385
VerifyOrReturnValue(Instance().mDevicesMap.Contains(index), CHIP_ERROR_INTERNAL);
385386

386387
auto *device = Instance().mDevicesMap[index].mDevice;
387388

389+
VerifyOrReturnError(device != nullptr, CHIP_ERROR_INTERNAL);
390+
388391
/* Handle reads for the generic information for all bridged devices. Provide a valid answer even if device state
389392
* is unreachable. */
390393
switch (clusterId) {

0 commit comments

Comments
 (0)