]> 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>
Tue, 10 Apr 2018 08:21:49 +0000 (16:21 +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>
src/crush/CrushWrapper.cc

index c72a8acedf2d4ff8e9904f9be47f8b03fb62bc40..f6c19045b1254d4bb606a2bbe15b65f5bd94b6c4 100644 (file)
@@ -3139,6 +3139,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
@@ -3182,6 +3186,7 @@ int CrushWrapper::_choose_type_stack(
              ldout(cct, 10) << __func__ << " pos " << pos << " replace "
                             << *i << " -> " << item << dendl;
              replaced = true;
+              assert(i != orig.end());
              ++i;
              break;
            }
@@ -3189,6 +3194,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;
          }