[tor-commits] [tor/master] Avoid division-by-zero in pathbias_check_*_success_count

nickm at torproject.org nickm at torproject.org
Fri Dec 16 16:26:18 UTC 2016


commit 526b0e2ce2c5d31c70eb3e48eda59b34e9eb681d
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Nov 23 13:05:22 2016 -0500

    Avoid division-by-zero in pathbias_check_*_success_count
---
 src/or/entrynodes.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index bd30078..860be9b 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -3402,10 +3402,13 @@ static void
 pathbias_check_use_success_count(entry_guard_t *node)
 {
   const or_options_t *options = get_options();
+  const double EPSILON = 1.0e-9;
+
   /* Note: We rely on the < comparison here to allow us to set a 0
    * rate and disable the feature entirely. If refactoring, don't
    * change to <= */
-  if (pathbias_get_use_success_count(node)/node->pb.use_attempts
+  if (node->pb.use_attempts > EPSILON &&
+      pathbias_get_use_success_count(node)/node->pb.use_attempts
       < pathbias_get_extreme_use_rate(options) &&
       pathbias_get_dropguards(options)) {
     node->pb.path_bias_disabled = 1;
@@ -3420,10 +3423,13 @@ static void
 pathbias_check_close_success_count(entry_guard_t *node)
 {
   const or_options_t *options = get_options();
+  const double EPSILON = 1.0e-9;
+
   /* Note: We rely on the < comparison here to allow us to set a 0
    * rate and disable the feature entirely. If refactoring, don't
    * change to <= */
-  if (pathbias_get_close_success_count(node)/node->pb.circ_attempts
+  if (node->pb.circ_attempts > EPSILON &&
+      pathbias_get_close_success_count(node)/node->pb.circ_attempts
       < pathbias_get_extreme_rate(options) &&
       pathbias_get_dropguards(options)) {
     node->pb.path_bias_disabled = 1;





More information about the tor-commits mailing list