Skip to content

Commit

Permalink
Check that we are on the Matter thread when we do ErrorStr.
Browse files Browse the repository at this point in the history
This uses a single static buffer, so using it from multiple threads can race on
writes to that buffer.  In the worst case, we could end up with that buffer not
null-terminated in a useful way.
  • Loading branch information
bzbarsky-apple committed Feb 24, 2023
1 parent 53142c7 commit 89a7ed9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ble/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ chip_test_suite("tests") {
public_deps = [
"${chip_root}/src/ble",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/platform",
"${nlunit_test_root}:nlunit-test",
]
}
1 change: 1 addition & 0 deletions src/lib/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ chip_test_suite("tests") {
public_deps = [
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/platform",
"${nlunit_test_root}:nlunit-test",
]
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/support/ErrorStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <lib/core/CHIPCore.h>
#include <lib/support/CodeUtils.h>
#include <platform/LockTracker.h>

namespace chip {

Expand All @@ -56,6 +57,7 @@ static ErrorFormatter * sErrorFormatterList = nullptr;
*/
DLL_EXPORT const char * ErrorStr(CHIP_ERROR err)
{
assertChipStackLockedByCurrentThread();
char * formattedError = sErrorStr;
uint16_t formattedSpace = sizeof(sErrorStr);

Expand Down

0 comments on commit 89a7ed9

Please sign in to comment.