diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-29 09:48:02 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-29 09:48:02 -0400 |
commit | 2b1b1def46395de573902169404238d38ce3070e (patch) | |
tree | a99fc69bb0ccff12e98db43b7b12f900315e3e42 /src/or | |
parent | ba7b6246b7dc6d75ccf28329c41ea1d688123127 (diff) | |
parent | 4d0ad34a92dff2be0b23e75ca5373054a5c9334a (diff) | |
download | tor-2b1b1def46395de573902169404238d38ce3070e.tar.gz tor-2b1b1def46395de573902169404238d38ce3070e.zip |
Merge remote-tracking branch 'teor/circuitstats-pareto-avoid-div-zero'
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/circuitstats.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/or/circuitstats.c b/src/or/circuitstats.c index c24259c22c..5336e4046e 100644 --- a/src/or/circuitstats.c +++ b/src/or/circuitstats.c @@ -1085,7 +1085,21 @@ circuit_build_times_calculate_timeout(circuit_build_times_t *cbt, tor_assert(1.0-quantile > 0); tor_assert(cbt->Xm > 0); - ret = cbt->Xm/pow(1.0-quantile,1.0/cbt->alpha); + /* If either alpha or p are 0, we would divide by zero, yielding an + * infinite (double) result; which would be clamped to INT32_MAX. + * Instead, initialise ret to INT32_MAX, and skip over these + * potentially illegal/trapping divides by zero. + */ + ret = INT32_MAX; + + if (cbt->alpha > 0) { + double p; + p = pow(1.0-quantile,1.0/cbt->alpha); + if (p > 0) { + ret = cbt->Xm/p; + } + } + if (ret > INT32_MAX) { ret = INT32_MAX; } |