]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon/MonClient: do not dereference auth_supported.end()
authorKefu Chai <kchai@redhat.com>
Tue, 26 Mar 2019 16:02:01 +0000 (00:02 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 26 Mar 2019 16:08:01 +0000 (00:08 +0800)
if we are unable to find a supported method in allowed_methods, we will
dereference `auth_supported.end()` for searching it in desperation.

Reported-by: xie xingguo <xie.xingguo@zte.com.cn>
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/MonClient.cc

index 2c36868c13c56c1d8cb6342251dcae5f874e716b..1ce68eb19a611424bd164c1f7c00b4582780c11f 100644 (file)
@@ -12,6 +12,8 @@
  * 
  */
 
+#include <algorithm>
+#include <iterator>
 #include <random>
 #include <boost/range/adaptor/map.hpp>
 #include <boost/range/adaptor/filtered.hpp>
@@ -1639,14 +1641,8 @@ int MonConnection::handle_auth_bad_method(
   auto p = std::find(auth_supported.begin(), auth_supported.end(),
                     old_auth_method);
   assert(p != auth_supported.end());
-
-  while (p != auth_supported.end()) {
-    ++p;
-    if (std::find(allowed_methods.begin(), allowed_methods.end(), *p) !=
-       allowed_methods.end()) {
-      break;
-    }
-  }
+  p = std::find_first_of(std::next(p), auth_supported.end(),
+                        allowed_methods.begin(), allowed_methods.end());
   if (p == auth_supported.end()) {
     lderr(cct) << __func__ << " server allowed_methods " << allowed_methods
               << " but i only support " << auth_supported << dendl;