From: Kefu Chai Date: Tue, 26 Mar 2019 16:02:01 +0000 (+0800) Subject: mon/MonClient: do not dereference auth_supported.end() X-Git-Tag: v15.0.0~68^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=998b1925bd6d19b2b32141b92de66b77027130a0;p=ceph-ci.git mon/MonClient: do not dereference auth_supported.end() 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 Signed-off-by: Kefu Chai --- diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 2c36868c13c..1ce68eb19a6 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -12,6 +12,8 @@ * */ +#include +#include #include #include #include @@ -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;