From da629d63ffbfb7ff357e75fb041ec27687962153 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sat, 14 Aug 2021 17:06:45 -0700 Subject: [PATCH] [srp-server] update how/where the host addresses are checked (#6927) This commit changes the check for the number of host addresses in a newly received SRP update message such that if we have a non-zero lease, we ensure that there is at least one valid address. It also moves this check from `ProcessHostDescriptionInstruction()` to after the Lease Option in the Additional Section is parsed (in `ProcessAdditionalSection()`) so that we check after we determine the host lease interval and whether the host is being removed or registered. --- src/core/net/srp_server.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/net/srp_server.cpp b/src/core/net/srp_server.cpp index 4914a848c..865452818 100644 --- a/src/core/net/srp_server.cpp +++ b/src/core/net/srp_server.cpp @@ -693,14 +693,10 @@ Error Server::ProcessHostDescriptionInstruction(Host & aHost, VerifyOrExit(aHost.GetFullName() != nullptr, error = kErrorFailed); VerifyOrExit(aHost.GetKey() != nullptr, error = kErrorFailed); - { - uint8_t hostAddressesNum; - aHost.GetAddresses(hostAddressesNum); - - // There MUST be at least one valid address if we have nonzero lease. - VerifyOrExit(aHost.GetLease() > 0 || hostAddressesNum > 0, error = kErrorFailed); - } + // We check the number of host addresses after processing of the + // Lease Option in the Addition Section and determining whether + // the host is being removed or registered. exit: return error; @@ -906,6 +902,16 @@ Error Server::ProcessAdditionalSection(Host * aHost, aHost->SetLease(leaseOption.GetLeaseInterval()); aHost->SetKeyLease(leaseOption.GetKeyLeaseInterval()); + if (aHost->GetLease() > 0) + { + uint8_t hostAddressesNum; + + aHost->GetAddresses(hostAddressesNum); + + // There MUST be at least one valid address if we have nonzero lease. + VerifyOrExit(hostAddressesNum > 0, error = kErrorFailed); + } + // SIG(0). sigOffset = aOffset;