]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonClient: do not dereference auth_supported.end() 27215/head
authorKefu Chai <kchai@redhat.com>
Tue, 26 Mar 2019 16:02:01 +0000 (00:02 +0800)
committerSage Weil <sage@redhat.com>
Wed, 27 Mar 2019 14:41:59 +0000 (09:41 -0500)
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>
(cherry picked from commit 998b1925bd6d19b2b32141b92de66b77027130a0)

src/mon/MonClient.cc

index bf4e12407594674b6f9a2967657e49b121a07b88..37e4c347f5b8e738c7b348aac535aab6073a12d7 100644 (file)
@@ -12,6 +12,8 @@
  * 
  */
 
+#include <algorithm>
+#include <iterator>
 #include <random>
 
 #include "include/scope_guard.h"
@@ -1602,14 +1604,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;