mirror of
https://github.com/espressif/openthread.git
synced 2026-07-31 08:07:47 +00:00
[srp] clear name on ExtractLabels() failure in AdvertisingProxy (#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.
This commit is contained in:
@@ -1152,7 +1152,10 @@ void AdvertisingProxy::UnregisterKey(const char *aName, const char *aServiceType
|
||||
|
||||
void AdvertisingProxy::CopyNameAndRemoveDomain(DnsName &aName, const char *aFullName)
|
||||
{
|
||||
IgnoreError(Dns::Name::ExtractLabels(aFullName, Get<Server>().GetDomain(), aName, sizeof(aName)));
|
||||
if (Dns::Name::ExtractLabels(aFullName, Get<Server>().GetDomain(), aName, sizeof(aName)) != kErrorNone)
|
||||
{
|
||||
aName[0] = kNullChar;
|
||||
}
|
||||
}
|
||||
|
||||
void AdvertisingProxy::HandleRegistered(otInstance *aInstance, otPlatDnssdRequestId aRequestId, otError aError)
|
||||
|
||||
Reference in New Issue
Block a user