Skip to content

Commit

Permalink
Fix potential integer overflow in Balance
Browse files Browse the repository at this point in the history
An usize overflow can occur in `Balance::promote_to_ready` when `self.not_ready` has length 0.

See my comment here: #39 (comment)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Jan 25, 2018
1 parent 777888d commit ec0c819
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tower-balance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
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.
for idx in (0..n-1).rev() {
for idx in (0..n.saturating_sub(1)).rev() {
let is_ready = {
let (_, svc) = self.not_ready
.get_index_mut(idx)
Expand Down

0 comments on commit ec0c819

Please sign in to comment.