Skip to content

Commit

Permalink
[chip-tool] Do not call ErrorStr after RunCommand in interactive mode…
Browse files Browse the repository at this point in the history
… as ErrorStr use a single static buffer to compute the error string and in interactive mode the stack continue to do some work and it may race
  • Loading branch information
vivien-apple committed Feb 24, 2023
1 parent 98ff3a5 commit a4a0933
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 8 additions & 0 deletions examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class CHIPCommand : public Command
void SetCommandExitStatus(CHIP_ERROR status)
{
mCommandExitStatus = status;
// In interactive mode the stack is not shut down once a command is ended.
// That means calling `ErrorStr(err)` from the main thread when command
// completion is signaled may race since `ErrorStr` uses a static sErrorStr
// buffer for computing the error string. Call it here instead.
if (IsInteractive() && CHIP_NO_ERROR != status)
{
ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(status));
}
StopWaiting();
}

Expand Down
4 changes: 1 addition & 3 deletions examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ int Commands::RunInteractive(const char * command)
delete[] argv[i];
}

VerifyOrReturnValue(CHIP_NO_ERROR == err, EXIT_FAILURE, ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(err)));

return EXIT_SUCCESS;
return (err == CHIP_NO_ERROR) ? EXIT_SUCCESS : EXIT_FAILURE;
}

CHIP_ERROR Commands::RunCommand(int argc, char ** argv, bool interactive)
Expand Down

0 comments on commit a4a0933

Please sign in to comment.