[dns-name] require message offset to point to DNS header (#6101)

This commit contains two changes in `Dns::Name` class. When reading or
parsing names/labels from a `Message`, we require that the message
offset (i.e., `aMessage.GetOffset()`) to be set by the caller to point
to the start of the DNS header in the message. This is then used to
decode compressed DNS names. This change helps simplify the code and
removes the need to pass `aHeaderOffset` as a separate parameter. The
second change is to the `ParseName()` implementation which now always
goes through and parses the entire compressed name before returning.
This ensures that we correctly detect invalid compressed names when
parsing the name in a message.
This commit is contained in:
Abtin Keshavarzian
2021-01-22 17:38:56 -08:00
committed by GitHub
parent 98dea576fd
commit e12178a256
6 changed files with 64 additions and 86 deletions
+3 -5
View File
@@ -339,14 +339,12 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag
QueryMetadata queryMetadata;
AaaaRecord record;
Message * message = nullptr;
uint16_t offset;
uint16_t offset = aMessage.GetOffset();
SuccessOrExit(aMessage.Read(aMessage.GetOffset(), responseHeader));
SuccessOrExit(aMessage.Read(offset, responseHeader));
VerifyOrExit(responseHeader.GetType() == Header::kTypeResponse && responseHeader.GetQuestionCount() == 1 &&
!responseHeader.IsTruncationFlagSet());
aMessage.MoveOffset(sizeof(responseHeader));
offset = aMessage.GetOffset();
offset += sizeof(responseHeader);
VerifyOrExit((message = FindQueryById(responseHeader.GetMessageId())) != nullptr);
queryMetadata.ReadFrom(*message);
+19 -17
View File
@@ -207,12 +207,20 @@ otError Name::ParseName(const Message &aMessage, uint16_t &aOffset)
{
error = iterator.GetNextLabel();
VerifyOrExit((error == OT_ERROR_NONE) || (error == OT_ERROR_NOT_FOUND));
if (iterator.IsEndOffsetSet())
switch (error)
{
case OT_ERROR_NONE:
break;
case OT_ERROR_NOT_FOUND:
// We reached the end of name successfully.
aOffset = iterator.mNameEndOffset;
ExitNow(error = OT_ERROR_NONE);
error = OT_ERROR_NONE;
OT_FALL_THROUGH;
default:
ExitNow();
}
}
@@ -220,14 +228,10 @@ exit:
return error;
}
otError Name::ReadLabel(const Message &aMessage,
uint16_t & aOffset,
uint16_t aHeaderOffset,
char * aLabelBuffer,
uint8_t & aLabelLength)
otError Name::ReadLabel(const Message &aMessage, uint16_t &aOffset, char *aLabelBuffer, uint8_t &aLabelLength)
{
otError error;
LabelIterator iterator(aMessage, aOffset, aHeaderOffset);
LabelIterator iterator(aMessage, aOffset);
SuccessOrExit(error = iterator.GetNextLabel());
SuccessOrExit(error = iterator.ReadLabel(aLabelBuffer, aLabelLength, /* aAllowDotCharInLabel */ true));
@@ -237,14 +241,10 @@ exit:
return error;
}
otError Name::ReadName(const Message &aMessage,
uint16_t & aOffset,
uint16_t aHeaderOffset,
char * aNameBuffer,
uint16_t aNameBufferSize)
otError Name::ReadName(const Message &aMessage, uint16_t &aOffset, char *aNameBuffer, uint16_t aNameBufferSize)
{
otError error;
LabelIterator iterator(aMessage, aOffset, aHeaderOffset);
LabelIterator iterator(aMessage, aOffset);
bool firstLabel = true;
uint8_t labelLength;
@@ -340,7 +340,9 @@ otError Name::LabelIterator::GetNextLabel(void)
mNameEndOffset = mNextLabelOffset + sizeof(uint16_t);
}
mNextLabelOffset = mHeaderOffset + (HostSwap16(pointerValue) & kPointerLabelOffsetMask);
// `mMessage.GetOffset()` must point to the start of the
// DNS header.
mNextLabelOffset = mMessage.GetOffset() + (HostSwap16(pointerValue) & kPointerLabelOffsetMask);
// Go back through the `while(true)` loop to get the next label.
}
+9 -18
View File
@@ -582,7 +582,8 @@ public:
/**
* This static method parses and skips over a full name in a message.
*
* @param[in] aMessage The message to parse the name from.
* @param[in] aMessage The message to parse the name from. `aMessage.GetOffset()` MUST point to
* the start of DNS header (this is used to handle compressed names).
* @param[inout] aOffset On input the offset in @p aMessage pointing to the start of the name field.
* On exit (when parsed successfully), @p aOffset is updated to point to the byte
* after the end of name field.
@@ -605,11 +606,11 @@ public:
* Unlike `ReadName()` which requires and verifies that the read label to contain no dot '.' character, this method
* allows the read label to include any character.
*
* @param[in] aMessage The message to read the label from.
* @param[in] aMessage The message to read the label from. `aMessage.GetOffset()` MUST point to
* the start of DNS header (this is used to handle compressed names).
* @param[inout] aOffset On input, the offset in @p aMessage pointing to the start of the label to read.
* On exit, when successfully read, @p aOffset is updated to point to the start of
* the next label.
* @param[in] aHeaderOffset The offset in @p aMessage to the start of the DNS header.
* @param[out] aLabelBuffer A pointer to a char array to output the read label as a null-terminated C string.
* @param[inout] aLabelLength On input, the maximum number chars in @p aLabelBuffer array.
* On output, when label is successfully read, @aLabelLength is updated to return
@@ -622,11 +623,7 @@ public:
* @retval OT_ERROR_NO_BUFS Label could not fit in @p aLabelLength chars.
*
*/
static otError ReadLabel(const Message &aMessage,
uint16_t & aOffset,
uint16_t aHeaderOffset,
char * aLabelBuffer,
uint8_t & aLabelLength);
static otError ReadLabel(const Message &aMessage, uint16_t &aOffset, char *aLabelBuffer, uint8_t &aLabelLength);
/**
* This static method reads a full name from a message.
@@ -637,11 +634,11 @@ public:
* This method verifies that the read labels in message do not contain any dot character, otherwise it returns
* `OT_ERROR_PARSE`).
*
* @param[in] aMessage The message to read the name from.
* @param[in] aMessage The message to read the name from. `aMessage.GetOffset()` MUST point to
* the start of DNS header (this is used to handle compressed names).
* @param[inout] aOffset On input, the offset in @p aMessage pointing to the start of the name field.
* On exit (when parsed successfully), @p aOffset is updated to point to the byte
* after the end of name field.
* @param[in] aHeaderOffset The offset in @p aMessage to the start of the DNS header.
* @param[out] aNameBuffer A pointer to a char array to output the read name as a null-terminated C string.
* @param[inout] aNameBufferSize The maximum number chars in @p aNameBuffer array.
*
@@ -650,11 +647,7 @@ public:
* @retval OT_ERROR_NO_BUFS Name could not fit in @p aNameBufferSize chars.
*
*/
static otError ReadName(const Message &aMessage,
uint16_t & aOffset,
uint16_t aHeaderOffset,
char * aNameBuffer,
uint16_t aNameBufferSize);
static otError ReadName(const Message &aMessage, uint16_t &aOffset, char *aNameBuffer, uint16_t aNameBufferSize);
private:
enum : char
@@ -689,9 +682,8 @@ private:
kUnsetNameEndOffset = 0, // Special value indicating `mNameEndOffset` is not yet set.
};
LabelIterator(const Message &aMessage, uint16_t aLabelOffset, uint16_t aHeaderOffset = 0)
LabelIterator(const Message &aMessage, uint16_t aLabelOffset)
: mMessage(aMessage)
, mHeaderOffset(aHeaderOffset)
, mNextLabelOffset(aLabelOffset)
, mNameEndOffset(kUnsetNameEndOffset)
{
@@ -702,7 +694,6 @@ private:
otError ReadLabel(char *aLabelBuffer, uint8_t &aLabelLength, bool aAllowDotCharInLabel) const;
const Message &mMessage; // Message to read labels from.
const uint16_t mHeaderOffset; // Offset in `mMessage` to the start of DNS header.
uint16_t mLabelStartOffset; // Offset in `mMessage` to the first char of current label text.
uint8_t mLabelLength; // Length of current label (number of chars).
uint16_t mNextLabelOffset; // Offset in `mMessage` to the start of the next label.
+13 -21
View File
@@ -529,8 +529,6 @@ void Server::HandleDnsUpdate(Message & aMessage,
Dns::Zone zone;
Host * host = nullptr;
uint16_t headerOffset = aOffset - sizeof(aDnsHeader);
otLogInfoSrp("[server] receive DNS update from %s", aMessageInfo.GetPeerAddr().ToString().AsCString());
SuccessOrExit(error = ProcessZoneSection(aMessage, aDnsHeader, aOffset, zone));
@@ -550,10 +548,10 @@ void Server::HandleDnsUpdate(Message & aMessage,
host = Host::New(GetInstance());
VerifyOrExit(host != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = ProcessUpdateSection(*host, aMessage, aDnsHeader, zone, headerOffset, aOffset));
SuccessOrExit(error = ProcessUpdateSection(*host, aMessage, aDnsHeader, zone, aOffset));
// Parse lease time and validate signature.
SuccessOrExit(error = ProcessAdditionalSection(host, aMessage, aDnsHeader, headerOffset, aOffset));
SuccessOrExit(error = ProcessAdditionalSection(host, aMessage, aDnsHeader, aOffset));
HandleUpdate(aDnsHeader, host, aMessageInfo);
@@ -593,7 +591,6 @@ otError Server::ProcessUpdateSection(Host & aHost,
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t & aOffset)
{
otError error = OT_ERROR_NONE;
@@ -604,15 +601,15 @@ otError Server::ProcessUpdateSection(Host & aHost,
// 0. Enumerate over all Service Discovery Instructions before processing any other records.
// So that we will know whether a name is a hostname or service instance name when processing
// a "Delete All RRsets from a name" record.
error = ProcessServiceDiscoveryInstructions(aHost, aMessage, aDnsHeader, aZone, aHeaderOffset, aOffset);
error = ProcessServiceDiscoveryInstructions(aHost, aMessage, aDnsHeader, aZone, aOffset);
SuccessOrExit(error);
// 1. Enumerate over all RRs to build the Host Description Instruction.
error = ProcessHostDescriptionInstruction(aHost, aMessage, aDnsHeader, aZone, aHeaderOffset, aOffset);
error = ProcessHostDescriptionInstruction(aHost, aMessage, aDnsHeader, aZone, aOffset);
SuccessOrExit(error);
// 2. Enumerate over all RRs to build the Service Description Insutructions.
error = ProcessServiceDescriptionInstructions(aHost, aMessage, aDnsHeader, aZone, aHeaderOffset, aOffset);
error = ProcessServiceDescriptionInstructions(aHost, aMessage, aDnsHeader, aZone, aOffset);
SuccessOrExit(error);
// 3. Verify that there are no name conflicts.
@@ -626,7 +623,6 @@ otError Server::ProcessHostDescriptionInstruction(Host & aHost
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t aOffset)
{
otError error;
@@ -638,7 +634,7 @@ otError Server::ProcessHostDescriptionInstruction(Host & aHost
char name[Dns::Name::kMaxLength + 1];
Dns::ResourceRecord record;
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, name, sizeof(name)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, name, sizeof(name)));
SuccessOrExit(error = aMessage.Read(aOffset, record));
if (record.GetClass() == Dns::ResourceRecord::kClassAny)
@@ -732,7 +728,6 @@ otError Server::ProcessServiceDiscoveryInstructions(Host & aHo
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t aOffset)
{
otError error = OT_ERROR_NONE;
@@ -744,15 +739,14 @@ otError Server::ProcessServiceDiscoveryInstructions(Host & aHo
char serviceName[Dns::Name::kMaxLength + 1];
Service * service;
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, name, sizeof(name)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, name, sizeof(name)));
SuccessOrExit(error = aMessage.Read(aOffset, record));
aOffset += sizeof(record);
if (record.GetType() == Dns::ResourceRecord::kTypePtr)
{
SuccessOrExit(error =
Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, serviceName, sizeof(serviceName)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, serviceName, sizeof(serviceName)));
}
else
{
@@ -782,7 +776,6 @@ otError Server::ProcessServiceDescriptionInstructions(Host & a
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t & aOffset)
{
Service *service;
@@ -793,7 +786,7 @@ otError Server::ProcessServiceDescriptionInstructions(Host & a
char name[Dns::Name::kMaxLength + 1];
Dns::ResourceRecord record;
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, name, sizeof(name)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, name, sizeof(name)));
SuccessOrExit(error = aMessage.Read(aOffset, record));
if (record.GetClass() == Dns::ResourceRecord::kClassAny)
@@ -820,7 +813,7 @@ otError Server::ProcessServiceDescriptionInstructions(Host & a
SuccessOrExit(error = aMessage.Read(aOffset, srvRecord));
aOffset += sizeof(srvRecord);
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, hostName, hostNameLength));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, hostName, hostNameLength));
VerifyOrExit(aHost.Matches(hostName), error = OT_ERROR_FAILED);
service = aHost.FindService(name);
@@ -869,7 +862,6 @@ bool Server::IsValidDeleteAllRecord(const Dns::ResourceRecord &aRecord)
otError Server::ProcessAdditionalSection(Host * aHost,
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
uint16_t aHeaderOffset,
uint16_t & aOffset)
{
otError error = OT_ERROR_NONE;
@@ -886,7 +878,7 @@ otError Server::ProcessAdditionalSection(Host * aHost,
// EDNS(0) Update Lease Option.
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, name, sizeof(name)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, name, sizeof(name)));
SuccessOrExit(error = aMessage.Read(aOffset, optRecord));
SuccessOrExit(error = aMessage.Read(aOffset + sizeof(optRecord), leaseOption));
VerifyOrExit(leaseOption.IsValid(), error = OT_ERROR_FAILED);
@@ -900,7 +892,7 @@ otError Server::ProcessAdditionalSection(Host * aHost,
// SIG(0).
sigOffset = aOffset;
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, name, sizeof(name)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, name, sizeof(name)));
SuccessOrExit(error = aMessage.Read(aOffset, sigRecord));
VerifyOrExit(sigRecord.IsValid(), error = OT_ERROR_PARSE);
@@ -911,7 +903,7 @@ otError Server::ProcessAdditionalSection(Host * aHost,
// implemented because the end device may not be able to get
// the synchronized date/time.
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, aHeaderOffset, signerName, sizeof(signerName)));
SuccessOrExit(error = Dns::Name::ReadName(aMessage, aOffset, signerName, sizeof(signerName)));
signatureLength = sigRecord.GetLength() - (aOffset - sigRdataOffset);
aOffset += signatureLength;
-5
View File
@@ -553,12 +553,10 @@ private:
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t & aOffset);
otError ProcessAdditionalSection(Host * aHost,
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
uint16_t aHeaderOffset,
uint16_t & aOffset);
otError VerifySignature(const Dns::Ecdsa256KeyRecord &aKey,
const Message & aMessage,
@@ -576,19 +574,16 @@ private:
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t aOffset);
static otError ProcessServiceDiscoveryInstructions(Host & aHost,
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t aOffset);
static otError ProcessServiceDescriptionInstructions(Host & aHost,
const Message & aMessage,
const Dns::UpdateHeader &aDnsHeader,
const Dns::Zone & aZone,
uint16_t aHeaderOffset,
uint16_t & aOffset);
static bool IsValidDeleteAllRecord(const Dns::ResourceRecord &aRecord);
+20 -20
View File
@@ -115,6 +115,8 @@ void TestDnsName(void)
messagePool = &instance->Get<MessagePool>();
VerifyOrQuit((message = messagePool->New(Message::kTypeIp6, 0)) != nullptr, "Message::New failed");
message->SetOffset(0);
printf("----------------------------------------------------------------\n");
printf("Append names, check encoded bytes, parse name and read labels:\n");
@@ -143,7 +145,7 @@ void TestDnsName(void)
for (uint8_t index = 0; test.mLabels[index] != nullptr; index++)
{
labelLength = sizeof(label);
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, 0, label, labelLength), "Name::ReadLabel() failed");
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength), "Name::ReadLabel() failed");
printf("Label[%d] = \"%s\"\n", index, label);
@@ -152,12 +154,12 @@ void TestDnsName(void)
}
labelLength = sizeof(label);
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, 0, label, labelLength) == OT_ERROR_NOT_FOUND,
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength) == OT_ERROR_NOT_FOUND,
"Name::ReadLabel() failed at end of the name");
// Read entire name
offset = 0;
SuccessOrQuit(Dns::Name::ReadName(*message, offset, 0, name, sizeof(name)), "Name::ReadName() failed");
SuccessOrQuit(Dns::Name::ReadName(*message, offset, name, sizeof(name)), "Name::ReadName() failed");
printf("Read name =\"%s\"\n", name);
@@ -167,10 +169,10 @@ void TestDnsName(void)
// Read entire name with different name buffer sizes (just right and one byte off the expected size)
offset = 0;
SuccessOrQuit(
Dns::Name::ReadName(*message, offset, 0, name, static_cast<uint16_t>(strlen(test.mExpectedReadName) + 1)),
Dns::Name::ReadName(*message, offset, name, static_cast<uint16_t>(strlen(test.mExpectedReadName) + 1)),
"Name::ReadName() failed with exact name buffer size");
offset = 0;
VerifyOrQuit(Dns::Name::ReadName(*message, offset, 0, name,
VerifyOrQuit(Dns::Name::ReadName(*message, offset, name,
static_cast<uint16_t>(strlen(test.mExpectedReadName))) == OT_ERROR_NO_BUFS,
"Name::ReadName() did not fail with too small name buffer size");
}
@@ -295,6 +297,8 @@ void TestDnsCompressedName(void)
SuccessOrQuit(message->Append(index), "Message::Append() failed");
}
message->SetOffset(kHeaderOffset);
name1Offset = message->GetLength();
SuccessOrQuit(Dns::Name::AppendName(kName, *message), "Name::AppendName() failed");
@@ -348,8 +352,7 @@ void TestDnsCompressedName(void)
for (const char *nameLabel : kName1Labels)
{
labelLength = sizeof(label);
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength),
"Name::ReadLabel() failed");
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength), "Name::ReadLabel() failed");
printf("label: \"%s\"\n", label);
VerifyOrQuit(strcmp(label, nameLabel) == 0, "Name::ReadLabel() did not get expected label");
@@ -357,11 +360,11 @@ void TestDnsCompressedName(void)
}
labelLength = sizeof(label);
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength) == OT_ERROR_NOT_FOUND,
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength) == OT_ERROR_NOT_FOUND,
"Name::ReadLabel() failed at end of the name");
offset = name1Offset;
SuccessOrQuit(Dns::Name::ReadName(*message, offset, kHeaderOffset, name, sizeof(name)), "Name::ReadName() failed");
SuccessOrQuit(Dns::Name::ReadName(*message, offset, name, sizeof(name)), "Name::ReadName() failed");
printf("Read name =\"%s\"\n", name);
VerifyOrQuit(strcmp(name, kExpectedReadName1) == 0, "Name::ReadName() did not return expected name");
VerifyOrQuit(offset == name1Offset + sizeof(kEncodedName), "Name::ReadName() returned incorrect offset");
@@ -381,8 +384,7 @@ void TestDnsCompressedName(void)
for (const char *nameLabel : kName2Labels)
{
labelLength = sizeof(label);
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength),
"Name::ReadLabel() failed");
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength), "Name::ReadLabel() failed");
printf("label: \"%s\"\n", label);
VerifyOrQuit(strcmp(label, nameLabel) == 0, "Name::ReadLabel() did not get expected label");
@@ -390,11 +392,11 @@ void TestDnsCompressedName(void)
}
labelLength = sizeof(label);
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength) == OT_ERROR_NOT_FOUND,
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength) == OT_ERROR_NOT_FOUND,
"Name::ReadLabel() failed at end of the name");
offset = name2Offset;
SuccessOrQuit(Dns::Name::ReadName(*message, offset, kHeaderOffset, name, sizeof(name)), "Name::ReadName() failed");
SuccessOrQuit(Dns::Name::ReadName(*message, offset, name, sizeof(name)), "Name::ReadName() failed");
printf("Read name =\"%s\"\n", name);
VerifyOrQuit(strcmp(name, kExpectedReadName2) == 0, "Name::ReadName() did not return expected name");
VerifyOrQuit(offset == name2Offset + kName2EncodedSize, "Name::ReadName() returned incorrect offset");
@@ -414,8 +416,7 @@ void TestDnsCompressedName(void)
for (const char *nameLabel : kName3Labels)
{
labelLength = sizeof(label);
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength),
"Name::ReadLabel() failed");
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength), "Name::ReadLabel() failed");
printf("label: \"%s\"\n", label);
VerifyOrQuit(strcmp(label, nameLabel) == 0, "Name::ReadLabel() did not get expected label");
@@ -423,11 +424,11 @@ void TestDnsCompressedName(void)
}
labelLength = sizeof(label);
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength) == OT_ERROR_NOT_FOUND,
VerifyOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength) == OT_ERROR_NOT_FOUND,
"Name::ReadLabel() failed at end of the name");
offset = name3Offset;
SuccessOrQuit(Dns::Name::ReadName(*message, offset, kHeaderOffset, name, sizeof(name)), "Name::ReadName() failed");
SuccessOrQuit(Dns::Name::ReadName(*message, offset, name, sizeof(name)), "Name::ReadName() failed");
printf("Read name =\"%s\"\n", name);
VerifyOrQuit(strcmp(name, kExpectedReadName3) == 0, "Name::ReadName() did not return expected name");
VerifyOrQuit(offset == name3Offset + kName3EncodedSize, "Name::ReadName() returned incorrect offset");
@@ -447,8 +448,7 @@ void TestDnsCompressedName(void)
for (const char *nameLabel : kName4Labels)
{
labelLength = sizeof(label);
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, kHeaderOffset, label, labelLength),
"Name::ReadLabel() failed");
SuccessOrQuit(Dns::Name::ReadLabel(*message, offset, label, labelLength), "Name::ReadLabel() failed");
printf("label: \"%s\"\n", label);
VerifyOrQuit(strcmp(label, nameLabel) == 0, "Name::ReadLabel() did not get expected label");
@@ -457,7 +457,7 @@ void TestDnsCompressedName(void)
// `ReadName()` for name-4 should fails due to first label containing dot char.
offset = name4Offset;
VerifyOrQuit(Dns::Name::ReadName(*message, offset, kHeaderOffset, name, sizeof(name)) == OT_ERROR_PARSE,
VerifyOrQuit(Dns::Name::ReadName(*message, offset, name, sizeof(name)) == OT_ERROR_PARSE,
"Name::ReadName() did not fail with invalid label");
message->Free();