From 5af685a9c5353caec9002372420911c8a5079ea5 Mon Sep 17 00:00:00 2001 From: Baptiste Courtois Date: Mon, 26 Nov 2018 19:13:57 +0100 Subject: [PATCH] auth: geoip - forbid 0 as weight value In the case where the weight of all records is set to zero, former code was trying to compute probability by dividing by 0. Another motivation to forbid the use of the "zero" weight is that the desired behavior was not clear. --- docs/backends/geoip.rst | 2 +- modules/geoipbackend/geoipbackend.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/backends/geoip.rst b/docs/backends/geoip.rst index b556bb1cc2..6667988c47 100644 --- a/docs/backends/geoip.rst +++ b/docs/backends/geoip.rst @@ -220,7 +220,7 @@ These placeholders disable caching for the record completely: Using the ``weight`` attribute ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You can use record attributes to define weight. +You can use record attributes to define positive and non-zero weight. If this is given, only one record is chosen randomly based on the weight. Probability is calculated by summing up the weights and dividing each weight with the sum. diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 5ed467b6dd..4baabe2fe7 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -150,9 +150,9 @@ void GeoIPBackend::initialize() { rr.content = content; } else if (attr == "weight") { rr.weight = iter->second.as(); - if (rr.weight < 0) { - g_log<