From c89db880db86540bc97f7e56a2d84aca29b33596 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Tue, 10 Apr 2018 15:32:47 +0800 Subject: [PATCH] crush/CrushWrapper: fix potential invalid use of iterator In choose_leaf mode we normally should have a stack of 2 and hence below here we still need to re-check the iterator against the stack loop. Signed-off-by: xie xingguo (cherry picked from commit 4ec24128fddd84f529348e460e45606eff42fc03) --- src/crush/CrushWrapper.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 822f1d9c183be..72cbbd7872e6d 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -3111,6 +3111,10 @@ int CrushWrapper::_choose_type_stack( << " w " << w << dendl; vector o; auto tmpi = i; + if (i == orig.end()) { + ldout(cct, 10) << __func__ << " end of orig, break 0" << dendl; + break; + } for (auto from : w) { ldout(cct, 10) << " from " << from << dendl; // identify leaves under each choice. we use this to check whether any of these @@ -3154,6 +3158,7 @@ int CrushWrapper::_choose_type_stack( ldout(cct, 10) << __func__ << " pos " << pos << " replace " << *i << " -> " << item << dendl; replaced = true; + assert(i != orig.end()); ++i; break; } @@ -3161,6 +3166,7 @@ int CrushWrapper::_choose_type_stack( if (!replaced) { ldout(cct, 10) << __func__ << " pos " << pos << " keep " << *i << dendl; + assert(i != orig.end()); o.push_back(*i); ++i; } -- 2.39.5