Fix potential integer overflow in Balance (#40)

An usize overflow can occur in `Balance::promote_to_ready` when `self.not_ready` has length 0.

See my comment here: https://github.com/tower-rs/tower/pull/39#discussion_r163967979

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
Eliza Weisman 2018-01-25 14:43:45 -08:00 committed by GitHub
parent 777888da7d
commit 251509a200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -148,6 +148,11 @@ where
-> Result<(), Error<<D::Service as Service>::Error, D::DiscoverError>>
{
let n = self.not_ready.len();
if n == 0 {
trace!("promoting to ready: not_ready is empty, skipping.");
return Ok(());
}
debug!("promoting to ready: {}", n);
// Iterate through the not-ready endpoints from right to left to prevent removals
// from reordering services in a way that could prevent a service from being polled.