[dnssd] bound question count in ShouldForwardToUpstream() (#13533)

Validate the question count is within the range the server handles before
iterating over the questions, and share the `kMaxQuestionCount` bound with
`ParseQuestions()`.
This commit is contained in:
Anurag Mewar
2026-09-02 11:13:49 -07:00
committed by GitHub
parent 4df5e61bef
commit cedcc0c405
2 changed files with 7 additions and 2 deletions
+6 -2
View File
@@ -352,7 +352,7 @@ Server::ResponseCode Server::Request::ParseQuestions(uint8_t aTestMode, bool &aS
VerifyOrExit(!(aTestMode & kTestModeRejectMultiQuestionQuery));
VerifyOrExit(!(aTestMode & kTestModeIgnoreMultiQuestionQuery), aShouldRespond = false);
VerifyOrExit(questionCount == 2);
VerifyOrExit(questionCount == kMaxQuestionCount);
// Allow SRV and TXT questions for the same service
// instance name in the same query.
@@ -1107,15 +1107,19 @@ exit:
bool Server::ShouldForwardToUpstream(const Request &aRequest) const
{
bool shouldForward = false;
uint16_t questionCount = aRequest.mHeader.GetQuestionCount();
uint16_t readOffset;
Name::Buffer name;
VerifyOrExit(mEnableUpstreamQuery);
VerifyOrExit(aRequest.mHeader.IsRecursionDesiredFlagSet());
VerifyOrExit((questionCount > 0) && (questionCount <= kMaxQuestionCount));
readOffset = sizeof(Header);
for (uint16_t i = 0; i < aRequest.mHeader.GetQuestionCount(); i++)
for (uint16_t i = 0; i < questionCount; i++)
{
SuccessOrExit(Name::ReadName(*aRequest.mMessage, readOffset, name));
readOffset += sizeof(Question);
+1
View File
@@ -311,6 +311,7 @@ private:
static constexpr bool kBindUnspecifiedNetif = OPENTHREAD_CONFIG_DNSSD_SERVER_BIND_UNSPECIFIED_NETIF;
static constexpr uint32_t kQueryTimeout = OPENTHREAD_CONFIG_DNSSD_QUERY_TIMEOUT;
static constexpr uint16_t kMaxConcurrentUpstreamQueries = 32;
static constexpr uint16_t kMaxQuestionCount = 2;
static constexpr uint16_t kRrTypeA = ResourceRecord::kTypeA;
static constexpr uint16_t kRrTypeNs = ResourceRecord::kTypeNs;