Skip to content

Commit 7b200c7

Browse files
authored
[srp] clear name on ExtractLabels() failure in AdvertisingProxy (openthread#13061)
This commit updates `AdvertisingProxy::CopyNameAndRemoveDomain()` to properly handle potential errors returned by `Dns::Name::ExtractLabels()`. Previously, any error returned by `ExtractLabels()` was ignored, which could leave the output name buffer in an indeterminate state. With this change, if extracting the labels fails, the name buffer is explicitly cleared by setting its first character to `kNullChar`. This prevents subsequent code from using uninitialized or partially written data in the event of a parsing or buffer size error.
1 parent 35fe1f3 commit 7b200c7

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/core/net/srp_advertising_proxy.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,10 @@ void AdvertisingProxy::UnregisterKey(const char *aName, const char *aServiceType
11521152

11531153
void AdvertisingProxy::CopyNameAndRemoveDomain(DnsName &aName, const char *aFullName)
11541154
{
1155-
IgnoreError(Dns::Name::ExtractLabels(aFullName, Get<Server>().GetDomain(), aName, sizeof(aName)));
1155+
if (Dns::Name::ExtractLabels(aFullName, Get<Server>().GetDomain(), aName, sizeof(aName)) != kErrorNone)
1156+
{
1157+
aName[0] = kNullChar;
1158+
}
11561159
}
11571160

11581161
void AdvertisingProxy::HandleRegistered(otInstance *aInstance, otPlatDnssdRequestId aRequestId, otError aError)

0 commit comments

Comments
 (0)