[dnssd-server] fix TXT RR format when TXT length is zero (#7141)

This commit is contained in:
Simon Lin
2021-11-09 08:11:30 -08:00
committed by GitHub
parent dc9ce005f3
commit d1405ec185
+12 -4
View File
@@ -488,17 +488,25 @@ Error Server::AppendTxtRecord(Message & aMessage,
uint32_t aTtl,
NameCompressInfo &aCompressInfo)
{
Error error = kErrorNone;
TxtRecord txtRecord;
Error error = kErrorNone;
TxtRecord txtRecord;
const uint8_t kEmptyTxt = 0;
SuccessOrExit(error = AppendInstanceName(aMessage, aInstanceName, aCompressInfo));
txtRecord.Init();
txtRecord.SetTtl(aTtl);
txtRecord.SetLength(aTxtLength);
txtRecord.SetLength(aTxtLength > 0 ? aTxtLength : sizeof(kEmptyTxt));
SuccessOrExit(error = aMessage.Append(txtRecord));
error = aMessage.AppendBytes(aTxtData, aTxtLength);
if (aTxtLength > 0)
{
error = aMessage.AppendBytes(aTxtData, aTxtLength);
}
else
{
error = aMessage.Append(kEmptyTxt);
}
exit:
return error;