From: Nigel Jones Date: Thu, 22 Oct 2015 10:16:15 +0000 (+1300) Subject: Prevent SIGFPE in wrandom routine - Fixes Issue #2794 X-Git-Tag: dnsdist-1.0.0-alpha1~252^2~4^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d289442518bd8ce13ce141bb1164f9c4b12f1ce1;p=pdns Prevent SIGFPE in wrandom routine - Fixes Issue #2794 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. --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 5ef526fd2..bb3596d08 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -262,6 +262,11 @@ shared_ptr wrandom(const NumberedServerVector& servers, const C } } + + // Catch poss & sum are empty to avoid SIGFPE + if(poss.empty()) + return shared_ptr(); + 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())