From cf12ea5cd796aee11752dcba7fc402329a66c625 Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Mon, 16 Jul 2018 14:20:50 -0400 Subject: [PATCH] upstream: fix PriorityStateManager indexing (#3856) The PriorityStateManager is indexing off the end of an array when the priority is large enough: Risk Level: Low Testing: Verified that the out-of-bounds indexing is actually happening by testing with an additional assert. Docs Changes: N/A Release Notes: N/A Signed-off-by: Alex Konradi --- source/common/upstream/upstream_impl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index c3a3702f65a0..5a80405a2057 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -695,7 +695,8 @@ void PriorityStateManager::updateClusterPrioritySet( HostVectorSharedPtr hosts(std::move(current_hosts)); LocalityWeightsMap empty_locality_map; LocalityWeightsMap& locality_weights_map = - priority_state_.empty() ? empty_locality_map : priority_state_[priority].second; + priority_state_.size() > priority ? priority_state_[priority].second : empty_locality_map; + ASSERT(priority_state_.size() > priority || locality_weights_map.empty()); LocalityWeightsSharedPtr locality_weights; std::vector per_locality;