mirror of
https://github.com/espressif/openthread.git
synced 2026-11-12 01:11:11 +00:00
[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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user