Skip to content

Commit

Permalink
Don't clobber chip-tool error
Browse files Browse the repository at this point in the history
#### Problem

82cf1b1 (PR project-chip#9086) could clobber a returned error code with a
different value `GetCommandExitStatus()`, which could lead to `chip-tool`
exiting successfully when it shouldn't. (This doesn't actually happen
at present because nothing sets `err` after `RunCommand()`, but could
be triggered by otherwise innocuous code changes.)

#### Change overview

Check for an existing error in preference to `GetCommandExitStatus()`.

#### Testing

Manual run of `chip-tool` with edits.
  • Loading branch information
kpschoedel committed Sep 7, 2021
1 parent 9a177b3 commit 5560c29
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ int Commands::Run(int argc, char ** argv)
#endif // !CONFIG_USE_SEPARATE_EVENTLOOP

exit:
if ((err == CHIP_NO_ERROR) && (command != nullptr))
{
err = command->GetCommandExitStatus();
}
if (err != CHIP_NO_ERROR)
{
ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(err));
Expand All @@ -130,15 +134,6 @@ int Commands::Run(int argc, char ** argv)
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
#endif // CONFIG_USE_SEPARATE_EVENTLOOP

if (command)
{
err = command->GetCommandExitStatus();
if (err != CHIP_NO_ERROR)
{
ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(err));
}
}

if (command)
{
command->Shutdown();
Expand Down

0 comments on commit 5560c29

Please sign in to comment.