Skip to content

Commit

Permalink
[DiagnosticLogs] Allow TransferFileDesignator or size 0 (#32267)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Mar 8, 2024
1 parent cb34962 commit 2501624
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ constexpr uint8_t kMaxFileDesignatorLen = 32;
constexpr uint16_t kMaxFilePathLen = kMaxFileDesignatorLen + sizeof(kTmpDir) + 1;

// For testing a few file names trigger an error depending on the current 'phase'.
constexpr char kErrorOnTransferBegin[] = "Error:OnTransferBegin";
constexpr char kErrorOnTransferData[] = "Error:OnTransferData";
constexpr char kErrorOnTransferEnd[] = "Error:OnTransferEnd";
constexpr char kErrorOnTransferBegin[] = "Error:OnTransferBegin";
constexpr char kErrorOnTransferData[] = "Error:OnTransferData";
constexpr char kErrorOnTransferEnd[] = "Error:OnTransferEnd";
constexpr char kErrorTransferMethodNotSupported[] = "TransferMethodNotSupported.txt";

BDXDiagnosticLogsServerDelegate BDXDiagnosticLogsServerDelegate::sInstance;

Expand Down Expand Up @@ -136,8 +137,14 @@ CHIP_ERROR BDXDiagnosticLogsServerDelegate::OnTransferBegin(chip::bdx::BDXTransf
auto fileDesignator = transfer->GetFileDesignator();
LogFileDesignator("OnTransferBegin", fileDesignator);

VerifyOrReturnError(fileDesignator.size() != 0, CHIP_ERROR_UNKNOWN_RESOURCE_ID);

chip::CharSpan phaseErrorTarget(kErrorOnTransferBegin, sizeof(kErrorOnTransferBegin) - 1);
ReturnErrorOnFailure(CheckForErrorRequested(phaseErrorTarget, fileDesignator));

chip::CharSpan transferErrorTarget(kErrorTransferMethodNotSupported, sizeof(kErrorTransferMethodNotSupported) - 1);
VerifyOrReturnError(!transferErrorTarget.data_equal(fileDesignator), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);

ReturnErrorOnFailure(CheckFileDesignatorAllowed(mFileDesignators, fileDesignator));

char outputFilePath[kMaxFilePathLen] = { 0 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ void DiagnosticLogsServer::HandleLogRequestForBdx(CommandHandler * commandObj, c
// INVALID_COMMAND.
VerifyOrReturn(transferFileDesignator.HasValue(), commandObj->AddStatus(path, Status::InvalidCommand));

VerifyOrReturn(transferFileDesignator.Value().size() > 0, commandObj->AddStatus(path, Status::ConstraintError));

VerifyOrReturn(transferFileDesignator.Value().size() <= kMaxFileDesignatorLen,
commandObj->AddStatus(path, Status::ConstraintError));

Expand Down
1 change: 0 additions & 1 deletion src/protocols/bdx/BdxTransferProxyDiagnosticLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ CHIP_ERROR BDXTransferProxyDiagnosticLog::Init(TransferSession * transferSession
uint16_t fileDesignatorLength = 0;
auto fileDesignator = transferSession->GetFileDesignator(fileDesignatorLength);

VerifyOrReturnError(fileDesignatorLength > 0, CHIP_ERROR_INVALID_STRING_LENGTH);
VerifyOrReturnError(fileDesignatorLength <= ArraySize(mFileDesignator), CHIP_ERROR_INVALID_STRING_LENGTH);

mTransfer = transferSession;
Expand Down
8 changes: 8 additions & 0 deletions src/protocols/bdx/StatusCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ StatusCode GetBdxStatusCodeFromChipError(CHIP_ERROR error)
{
status = StatusCode::kBadMessageContents;
}
else if (error == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
status = StatusCode::kTransferMethodNotSupported;
}
else if (error == CHIP_ERROR_UNKNOWN_RESOURCE_ID)
{
status = StatusCode::kFileDesignatorUnknown;
}

return status;
}
Expand Down

0 comments on commit 2501624

Please sign in to comment.