From: Remi Gacogne Date: Fri, 22 Nov 2019 08:54:06 +0000 (+0100) Subject: dnsdist: Make sure that setConsistentHashingBalancingFactor() >= 0 X-Git-Tag: auth-4.3.0-beta1~47^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80ee5144d23acfdf115b30452c59ac25fdb34a15;p=thirdparty%2Fpdns.git dnsdist: Make sure that setConsistentHashingBalancingFactor() >= 0 --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 251a071f59..4976e3a667 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1593,7 +1593,14 @@ void setupLuaConfig(bool client) g_lua.writeFunction("setConsistentHashingBalancingFactor", [](double factor) { setLuaSideEffect(); - g_consistentHashBalancingFactor = factor; + if (factor >= 0) { + g_consistentHashBalancingFactor = factor; + } + else { + errlog("Invalid value passed to setConsistentHashingBalancingFactor()!"); + g_outputBuffer="Invalid value passed to setConsistentHashingBalancingFactor()!\n"; + return; + } }); g_lua.writeFunction("setRingBuffersSize", [](size_t capacity, boost::optional numberOfShards) { diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 4c3bb2cc52..71066f1d0c 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -896,7 +896,7 @@ shared_ptr chashed(const NumberedServerVector& servers, const D shared_ptr ret = nullptr, first = nullptr; double targetLoad = std::numeric_limits::max(); - if (g_consistentHashBalancingFactor != 0) { + if (g_consistentHashBalancingFactor > 0) { /* we start with one, representing the query we are currently handling */ double currentLoad = 1; for (const auto& pair : servers) {