Skip to content

Commit

Permalink
[Telink] Fix NotifyAdvertisingStopped with Null node
Browse files Browse the repository at this point in the history
Since in file src/platform/Zephyr/BLEAdvertisingArbiter.cpp
function InsertRequest obtains previous node using iteration
via slist - condition (prev == nullptr) is only true if slist is
empty. In that case NotifyAdvertisingStopped is always called
with Null and no Null checker inside the function.
As result crash.
  • Loading branch information
andriy-bilynskyy committed Sep 7, 2023
1 parent 5bdfb75 commit 2845794
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/platform/Zephyr/BLEAdvertisingArbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ CHIP_ERROR InsertRequest(Request & request)

if (prev == nullptr)
{
NotifyAdvertisingStopped(sys_slist_peek_head(&sRequests));
sys_slist_prepend(&sRequests, &request);
}
else
Expand All @@ -110,6 +109,13 @@ CHIP_ERROR InsertRequest(Request & request)
void CancelRequest(Request & request)
{
const bool isTopPriority = (sys_slist_peek_head(&sRequests) == &request);

// If cancelled request was top-priority, stop the advertising.
if (isTopPriority)
{
NotifyAdvertisingStopped(sys_slist_peek_head(&sRequests));
}

VerifyOrReturn(sys_slist_find_and_remove(&sRequests, &request));

// If cancelled request was top-priority, restart the advertising.
Expand Down

0 comments on commit 2845794

Please sign in to comment.