]> granicus.if.org Git - pdns/commitdiff
Prevent SIGFPE in wrandom routine - Fixes Issue #2794
authorNigel Jones <nigel@nigelj.com>
Thu, 22 Oct 2015 10:16:15 +0000 (23:16 +1300)
committerNigel Jones <nigel@nigelj.com>
Thu, 22 Oct 2015 10:20:52 +0000 (23:20 +1300)
When a selected pool is empty (no servers in the default pool) or all servers in
the pool are marked as down, a Floating Point Exception will trigger as the
situation isn't caught.

pdns/dnsdist.cc

index 5ef526fd24d09585f9422b1d99b7e7959fdff2e5..bb3596d083e323e50e96d381b9a1b9bf686e1928 100644 (file)
@@ -262,6 +262,11 @@ shared_ptr<DownstreamState> wrandom(const NumberedServerVector& servers, const C
 
     }
   }
+
+  // Catch poss & sum are empty to avoid SIGFPE
+  if(poss.empty())
+    return shared_ptr<DownstreamState>();
+
   int r = random() % sum;
   auto p = upper_bound(poss.begin(), poss.end(),r, [](int r, const decltype(poss)::value_type& a) { return  r < a.first;});
   if(p==poss.end())