]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Make sure we don't divide by zero in Lua's pickwhashed() 9044/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Apr 2020 13:10:56 +0000 (15:10 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Apr 2020 13:10:56 +0000 (15:10 +0200)
pdns/lua-record.cc

index 7ef5bf6fe18d593603d6a32cc6b55677c647cac1..ca46307a3727cef75e570df1a8e5d0000de38143 100644 (file)
@@ -344,6 +344,10 @@ static ComboAddress pickwhashed(const ComboAddress& bestwho, vector<pair<int,Com
     sum += i.first;
     pick.push_back({sum, i.second});
   }
+  if (sum == 0) {
+    /* we should not have any weight of zero, but better safe than sorry */
+    return ComboAddress();
+  }
   ComboAddress::addressOnlyHash aoh;
   int r = aoh(bestwho) % sum;
   auto p = upper_bound(pick.begin(), pick.end(), r, [](int rarg, const decltype(pick)::value_type& a) { return rarg < a.first; });