From: xie xingguo Date: Tue, 10 Apr 2018 07:32:47 +0000 (+0800) Subject: crush/CrushWrapper: fix potential invalid use of iterator X-Git-Tag: v12.2.6~149^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c89db880db86540bc97f7e56a2d84aca29b33596;p=ceph.git 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) --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 822f1d9c183b..72cbbd7872e6 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; }