From: Pieter Lexis Date: Tue, 1 Jun 2021 11:18:54 +0000 (+0200) Subject: Make some cookie sizes constant, fix nits X-Git-Tag: dnsdist-1.7.0-alpha1~3^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=964007e2f4585d1aad6cccd5cd7d7f9df5617d28;p=thirdparty%2Fpdns.git Make some cookie sizes constant, fix nits --- diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 3c2bee68eb..b094b1d720 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -585,8 +585,8 @@ void mainthread() #ifdef HAVE_CRYPTO_SHORTHASH // we can do siphash-based cookies DNSPacket::s_doEDNSCookieProcessing = true; try { - if (::arg()["edns-cookie-secret"].size() != 32) { - throw std::range_error("wrong size (" + std::to_string(::arg()["edns-cookie-secret"].size()) + "), must be 32"); + if (::arg()["edns-cookie-secret"].size() != EDNSCOOKIESECRETSIZE) { + throw std::range_error("wrong size (" + std::to_string(::arg()["edns-cookie-secret"].size()) + "), must be " + std::to_string(EDNSCOOKIESECRETSIZE)); } DNSPacket::s_EDNSCookieKey = makeBytesFromHex(::arg()["edns-cookie-secret"]); } catch(const std::range_error &e) { diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index 67443945e8..131c2466a4 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -332,7 +332,7 @@ void DNSPacket::wrapup() if (d_haveednscookie) { if (d_eco.isWellFormed()) { - optsize += 24; + optsize += EDNSCOOKIEOPTSIZE; } } diff --git a/pdns/ednscookies.cc b/pdns/ednscookies.cc index 5805ff7a8d..cba399d4fd 100644 --- a/pdns/ednscookies.cc +++ b/pdns/ednscookies.cc @@ -19,10 +19,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" #include "ednscookies.hh" #include "misc.hh" -#include "config.h" #ifdef HAVE_CRYPTO_SHORTHASH #include #endif diff --git a/pdns/ednscookies.hh b/pdns/ednscookies.hh index 14d4653ead..0894d0e851 100644 --- a/pdns/ednscookies.hh +++ b/pdns/ednscookies.hh @@ -23,6 +23,9 @@ #include "namespaces.hh" #include "iputils.hh" +#define EDNSCOOKIESECRETSIZE 32 +#define EDNSCOOKIEOPTSIZE 24 + struct EDNSCookiesOpt { EDNSCookiesOpt(){}; diff --git a/pdns/misc.cc b/pdns/misc.cc index 494e49849f..278c472230 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -582,6 +582,7 @@ string makeBytesFromHex(const string &in) { throw std::range_error("odd number of bytes in hex string"); } string ret; + ret.reserve(in.size()); unsigned int num; for (size_t i = 0; i < in.size(); i+=2) { string numStr = in.substr(i, 2);