mirror of
https://github.com/espressif/openthread.git
synced 2026-09-07 01:30:11 +00:00
[dns] update Name::ValidateName() for max-length names (#12127)
`ValidateName()` did not correctly handle names that were exactly the maximum allowed length (`kMaxNameLength`). A name of this length is only valid if it ends with a trailing dot. Otherwise, when encoded, the added root label causes the encoded name to exceed the `kMaxEncodedLength` of 255 bytes. This commit updates `ValidateName()` to enforce that any name with length equal to `kMaxNameLength` must end with a dot character. It also updates the `TestDnsName` unit test to verify this corrected behavior, ensuring `ValidateName()` and `AppendName()` handle such names consistently.
This commit is contained in:
@@ -485,9 +485,13 @@ void TestDnsName(void)
|
||||
|
||||
IgnoreError(message->SetLength(0));
|
||||
|
||||
printf("\"%s\"\n", maxLengthName);
|
||||
printf("\"%s\" (len:%u)\n", maxLengthName, static_cast<uint16_t>(strlen(maxLengthName)));
|
||||
|
||||
SuccessOrQuit(Dns::Name::ValidateName(maxLengthName));
|
||||
|
||||
SuccessOrQuit(Dns::Name::AppendName(maxLengthName, *message));
|
||||
|
||||
VerifyOrQuit(message->GetLength() == Dns::Name::kMaxNameSize);
|
||||
}
|
||||
|
||||
printf("----------------------------------------------------------------\n");
|
||||
@@ -497,7 +501,9 @@ void TestDnsName(void)
|
||||
{
|
||||
IgnoreError(message->SetLength(0));
|
||||
|
||||
printf("\"%s\"\n", invalidName);
|
||||
printf("\"%s\" (len:%u)\n", invalidName, static_cast<uint16_t>(strlen(invalidName)));
|
||||
|
||||
VerifyOrQuit(Dns::Name::ValidateName(invalidName) != kErrorNone);
|
||||
|
||||
VerifyOrQuit(Dns::Name::AppendName(invalidName, *message) == kErrorInvalidArgs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user