[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:
whd
2021-08-27 12:42:07 -07:00
committed by GitHub
parent a4a4d8ceb8
commit 88950e15e1
3 changed files with 8 additions and 7 deletions
+3 -3
View File
@@ -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)
{
+4 -3
View File
@@ -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;
+1 -1
View File
@@ -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;