[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:
Abtin Keshavarzian
2025-11-08 11:25:23 -08:00
committed by GitHub
parent 6cc2a57742
commit cfe2999c94
2 changed files with 17 additions and 2 deletions
+8 -2
View File
@@ -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);
}