]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: fix potential invalid use of iterator
authorxie xingguo <xie.xingguo@zte.com.cn>
Tue, 10 Apr 2018 07:32:47 +0000 (15:32 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Thu, 12 Apr 2018 00:39:22 +0000 (08:39 +0800)
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 <xie.xingguo@zte.com.cn>
(cherry picked from commit 4ec24128fddd84f529348e460e45606eff42fc03)

src/crush/CrushWrapper.cc

index 822f1d9c183be517da956c739048fe4ac2139f3b..72cbbd7872e6d6d4444b319f460f494d8dfc29f3 100644 (file)
@@ -3111,6 +3111,10 @@ int CrushWrapper::_choose_type_stack(
                   << " w " << w << dendl;
     vector<int> 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;
          }