mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Avoid integer overflow in delay calculation.
This commit is contained in:
parent
864c42f4d6
commit
1fdf6e5814
@ -3796,11 +3796,15 @@ next_random_exponential_delay(int delay, int max_delay)
|
|||||||
|
|
||||||
/* How much are we willing to add to the delay? */
|
/* How much are we willing to add to the delay? */
|
||||||
int max_increment;
|
int max_increment;
|
||||||
|
const int multiplier = 4; /* no more than quintuple. */
|
||||||
|
|
||||||
if (delay)
|
if (delay && delay < (INT_MAX-1) / multiplier) {
|
||||||
max_increment = delay * 4; /* no more than quintuple. */
|
max_increment = delay * multiplier;
|
||||||
else
|
} else if (delay) {
|
||||||
|
max_increment = INT_MAX-1;
|
||||||
|
} else {
|
||||||
max_increment = 1; /* we're always willing to slow down a little. */
|
max_increment = 1; /* we're always willing to slow down a little. */
|
||||||
|
}
|
||||||
|
|
||||||
/* the + 1 here is so that we include the end of the interval */
|
/* the + 1 here is so that we include the end of the interval */
|
||||||
int increment = crypto_rand_int(max_increment+1);
|
int increment = crypto_rand_int(max_increment+1);
|
||||||
|
Loading…
Reference in New Issue
Block a user