]> granicus.if.org Git - pdns/commitdiff
auth: geoip - forbid 0 as weight value
authorBaptiste Courtois <b.courtois@criteo.com>
Mon, 26 Nov 2018 18:13:57 +0000 (19:13 +0100)
committerBaptiste Courtois <b.courtois@criteo.com>
Mon, 26 Nov 2018 18:13:57 +0000 (19:13 +0100)
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
modules/geoipbackend/geoipbackend.cc

index b556bb1cc2272633c1765274cc85ba786aa15928..6667988c47f198ad98e6dc9b899e1059b18b25a3 100644 (file)
@@ -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.
index 5ed467b6dd6228c5d93e73c4c14600cb21157ff7..4baabe2fe7c2cf4dc019a5a453c76e1054ecaa82 100644 (file)
@@ -150,9 +150,9 @@ void GeoIPBackend::initialize() {
                rr.content = content;
              } else if (attr == "weight") {
                rr.weight = iter->second.as<int>();
-               if (rr.weight < 0) {
-                 g_log<<Logger::Error<<"Weight cannot be negative for " << rr.qname << endl;
-                 throw PDNSException(string("Weight cannot be negative for ") + rr.qname.toLogString());
+               if (rr.weight <= 0) {
+                 g_log<<Logger::Error<<"Weight must be positive for " << rr.qname << endl;
+                 throw PDNSException(string("Weight must be positive for ") + rr.qname.toLogString());
                }
                rr.has_weight = true;
              } else if (attr == "ttl") {