]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Implement and use rfc1982LessThanOrEqual, use C++ style casts
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 10 Jun 2025 10:44:34 +0000 (12:44 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 10 Jun 2025 10:44:34 +0000 (12:44 +0200)
pdns/misc.hh
pdns/validate.cc

index ee03a5112cbe63b830fb56ec2e6cb8a5690ab3bf..0b2d0883833edec5fd1c77c17bdec0951b6505f2 100644 (file)
@@ -146,10 +146,16 @@ stringtok (Container &container, string const &in,
   }
 }
 
-template<typename T> bool rfc1982LessThan(T a, T b)
+template<typename T> bool rfc1982LessThan(T lhs, T rhs)
 {
   static_assert(std::is_unsigned_v<T>, "rfc1982LessThan only works for unsigned types");
-  return std::make_signed_t<T>(a - b) < 0;
+  return static_cast<std::make_signed_t<T>>(lhs - rhs) < 0;
+}
+
+template<typename T> bool rfc1982LessThanOrEqual(T lhs, T rhs)
+{
+  static_assert(std::is_unsigned_v<T>, "rfc1982LessThanOrEqual only works for unsigned types");
+  return static_cast<std::make_signed_t<T>>(lhs - rhs) <= 0;
 }
 
 // fills container with ranges, so {posbegin,posend}
index e1e38b50d16bcc44382eedf248deef0be2168c83..c7cec0549db2de1b98f311d8151692c5f869ae67 100644 (file)
@@ -973,12 +973,12 @@ dState getDenial(const cspmap_t &validrrsets, const DNSName& qname, const uint16
 
 bool isRRSIGNotExpired(const time_t now, const RRSIGRecordContent& sig)
 {
-  return rfc1982LessThan<uint32_t>(now, sig.d_sigexpire);
+  return rfc1982LessThanOrEqual<uint32_t>(now, sig.d_sigexpire);
 }
 
 bool isRRSIGIncepted(const time_t now, const RRSIGRecordContent& sig)
 {
-  return rfc1982LessThan<uint32_t>(sig.d_siginception - g_signatureInceptionSkew, now);
+  return rfc1982LessThanOrEqual<uint32_t>(sig.d_siginception - g_signatureInceptionSkew, now);
 }
 
 namespace {