mirror of
https://github.com/espressif/openthread.git
synced 2026-07-31 16:17:47 +00:00
[dns] allow Data Length = 0 while reading a TXT record (#6961)
RFC 6763 Section 6.1 states the following:
An empty TXT record containing zero strings is not allowed [RFC1035].
DNS-SD implementations MUST NOT emit empty TXT records. DNS-SD
clients MUST treat the following as equivalent:
o A TXT record containing a single zero byte.
(i.e., a single empty string.)
o An empty (zero-length) TXT record.
(This is not strictly legal, but should one be received, it should
be interpreted as the same as a single empty string.)
o No TXT record.
(i.e., an NXDOMAIN or no-error-no-answer response.)
This commit reflects the second requirement.
This commit is contained in:
@@ -1084,7 +1084,7 @@ Error TxtRecord::ReadTxtData(const Message &aMessage,
|
||||
|
||||
VerifyOrExit(GetLength() <= aTxtBufferSize, error = kErrorNoBufs);
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, aTxtBuffer, GetLength()));
|
||||
VerifyOrExit(VerifyTxtData(aTxtBuffer, GetLength()), error = kErrorParse);
|
||||
VerifyOrExit(VerifyTxtData(aTxtBuffer, GetLength(), /* aAllowEmpty */ true), error = kErrorParse);
|
||||
aTxtBufferSize = GetLength();
|
||||
aOffset += GetLength();
|
||||
|
||||
@@ -1092,13 +1092,13 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
bool TxtRecord::VerifyTxtData(const uint8_t *aTxtData, uint16_t aTxtLength)
|
||||
bool TxtRecord::VerifyTxtData(const uint8_t *aTxtData, uint16_t aTxtLength, bool aAllowEmpty)
|
||||
{
|
||||
bool valid = false;
|
||||
uint8_t curEntryLength = 0;
|
||||
|
||||
// Per RFC 1035, TXT-DATA MUST have one or more <character-string>s.
|
||||
VerifyOrExit(aTxtLength > 0);
|
||||
VerifyOrExit(aAllowEmpty || aTxtLength > 0);
|
||||
|
||||
for (uint16_t i = 0; i < aTxtLength; ++i)
|
||||
{
|
||||
|
||||
@@ -1677,13 +1677,14 @@ public:
|
||||
/**
|
||||
* This static method tests if a buffer contains valid encoded TXT data.
|
||||
*
|
||||
* @param[in] aTxtData The TXT data buffer.
|
||||
* @param[in] aTxtLength The length of the TXT data buffer.
|
||||
* @param[in] aTxtData The TXT data buffer.
|
||||
* @param[in] aTxtLength The length of the TXT data buffer.
|
||||
* @param[in] aAllowEmpty True if zero-length TXT data is allowed.
|
||||
*
|
||||
* @returns TRUE if @p aTxtData contains valid encoded TXT data, FALSE if not.
|
||||
*
|
||||
*/
|
||||
static bool VerifyTxtData(const uint8_t *aTxtData, uint16_t aTxtLength);
|
||||
static bool VerifyTxtData(const uint8_t *aTxtData, uint16_t aTxtLength, bool aAllowEmpty);
|
||||
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
|
||||
@@ -1526,7 +1526,7 @@ Error Server::Service::Description::SetTxtDataFromMessage(const Message &aMessag
|
||||
VerifyOrExit(txtData != nullptr, error = kErrorNoBufs);
|
||||
|
||||
VerifyOrExit(aMessage.ReadBytes(aOffset, txtData, aLength) == aLength, error = kErrorParse);
|
||||
VerifyOrExit(Dns::TxtRecord::VerifyTxtData(txtData, aLength), error = kErrorParse);
|
||||
VerifyOrExit(Dns::TxtRecord::VerifyTxtData(txtData, aLength, /* aAllowEmpty */ false), error = kErrorParse);
|
||||
|
||||
Instance::HeapFree(mTxtData);
|
||||
mTxtData = txtData;
|
||||
|
||||
Reference in New Issue
Block a user