]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
ensure server's weight is properly bounded
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 31 Jul 2018 16:03:28 +0000 (18:03 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 31 Jul 2018 16:03:28 +0000 (18:03 +0200)
pdns/dnsdist-lua-bindings.cc
pdns/dnsdist.cc

index 5eb25e1ad2b0b2d05e99226e443a2c58c7fd5475..c20aa10d5b873706fab3ed41a06a7485d5930a61 100644 (file)
@@ -115,7 +115,10 @@ void setupLuaBindings(bool client)
   g_lua.registerFunction("getName", &DownstreamState::getName);
   g_lua.registerFunction("getNameWithAddr", &DownstreamState::getNameWithAddr);
   g_lua.registerMember("upStatus", &DownstreamState::upStatus);
-  g_lua.registerMember("weight", &DownstreamState::weight);
+  g_lua.registerMember<int (DownstreamState::*)>("weight",
+    [](const DownstreamState& s) -> int {return s.weight;},
+    [](DownstreamState& s, int newWeight) {s.setWeight(newWeight);}
+  );
   g_lua.registerMember("order", &DownstreamState::order);
   g_lua.registerMember("name", &DownstreamState::name);
 
index f7500f8f4b9fb300a22b3c250a8d0bbb87bfb339..d839f4043d81cea28bbcec8c9b6995b2e880e46e 100644 (file)
@@ -649,6 +649,10 @@ void DownstreamState::setId(const boost::uuids::uuid& newId)
 
 void DownstreamState::setWeight(int newWeight)
 {
+  if (newWeight < 1) {
+    errlog("Error setting server's weight: downstream weight value must be greater than 0.");
+    return ;
+  }
   weight = newWeight;
   if (!hashes.empty()) {
     hash();