From d289442518bd8ce13ce141bb1164f9c4b12f1ce1 Mon Sep 17 00:00:00 2001 From: Nigel Jones Date: Thu, 22 Oct 2015 23:16:15 +1300 Subject: [PATCH] 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. --- pdns/dnsdist.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 5ef526fd24..bb3596d083 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()) -- 2.47.2