Skip to content

Commit bb769f9

Browse files
committed
Address comments
1 parent df967ae commit bb769f9

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/controller/CommissionerDiscoveryController.cpp

+27-10
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ void CommissionerDiscoveryController::OnUserDirectedCommissioningRequest(UDCClie
114114
Platform::CopyString(mCurrentInstance, state.GetInstanceName());
115115
mPendingConsent = true;
116116
char rotatingIdString[Dnssd::kMaxRotatingIdLen * 2 + 1];
117-
Encoding::BytesToUppercaseHexString(state.GetRotatingId(), state.GetRotatingIdLength(), rotatingIdString,
118-
sizeof(rotatingIdString));
117+
CHIP_ERROR err = Encoding::BytesToUppercaseHexString(state.GetRotatingId(), state.GetRotatingIdLength(), rotatingIdString,
118+
sizeof(rotatingIdString));
119+
if (err != CHIP_NO_ERROR)
120+
{
121+
ChipLogError(AppServer, "On UDC: could not convert rotating id to hex");
122+
rotatingIdString[0] = '\0';
123+
}
119124

120125
ChipLogDetail(Controller,
121126
"------PROMPT USER: %s is requesting permission to cast to this TV, approve? [" ChipLogFormatMEI
@@ -182,10 +187,16 @@ void CommissionerDiscoveryController::InternalOk()
182187
return;
183188
}
184189

185-
char rotatingIdString[Dnssd::kMaxRotatingIdLen * 2 + 1] = "";
186-
Encoding::BytesToUppercaseHexString(client->GetRotatingId(), client->GetRotatingIdLength(), rotatingIdString,
187-
sizeof(rotatingIdString));
188-
CharSpan rotatingIdSpan = CharSpan(rotatingIdString, strlen(rotatingIdString));
190+
char rotatingIdBuffer[Dnssd::kMaxRotatingIdLen * 2];
191+
size_t rotatingIdLength = client->GetRotatingIdLength();
192+
CHIP_ERROR err =
193+
Encoding::BytesToUppercaseHexBuffer(client->GetRotatingId(), rotatingIdLength, rotatingIdBuffer, sizeof(rotatingIdBuffer));
194+
if (err != CHIP_NO_ERROR)
195+
{
196+
ChipLogError(AppServer, "UX InternalOk: could not convert rotating id to hex");
197+
return;
198+
}
199+
CharSpan rotatingIdSpan(rotatingIdBuffer, 2 * rotatingIdLength);
189200

190201
uint8_t targetAppCount = client->GetNumTargetAppInfos();
191202
if (targetAppCount > 0)
@@ -360,10 +371,16 @@ void CommissionerDiscoveryController::InternalHandleContentAppPasscodeResponse()
360371
// - if CommissionerPasscode, then call new UX method to show passcode, send CDC
361372
if (passcode == 0 && client->GetCommissionerPasscode() && client->GetCdPort() != 0)
362373
{
363-
char rotatingIdString[Dnssd::kMaxRotatingIdLen * 2 + 1] = "";
364-
Encoding::BytesToUppercaseHexString(client->GetRotatingId(), client->GetRotatingIdLength(), rotatingIdString,
365-
sizeof(rotatingIdString));
366-
CharSpan rotatingIdSpan = CharSpan(rotatingIdString, strlen(rotatingIdString));
374+
char rotatingIdBuffer[Dnssd::kMaxRotatingIdLen * 2];
375+
size_t rotatingIdLength = client->GetRotatingIdLength();
376+
CHIP_ERROR err = Encoding::BytesToUppercaseHexBuffer(client->GetRotatingId(), rotatingIdLength, rotatingIdBuffer,
377+
sizeof(rotatingIdBuffer));
378+
if (err != CHIP_NO_ERROR)
379+
{
380+
ChipLogError(AppServer, "UX Ok - HandleContentAppPasscodeResponse: could not convert rotating id to hex");
381+
return;
382+
}
383+
CharSpan rotatingIdSpan(rotatingIdBuffer, 2 * rotatingIdLength);
367384

368385
// first step of commissioner passcode
369386
ChipLogError(AppServer, "UX Ok: commissioner passcode, sending CDC");

0 commit comments

Comments
 (0)