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: v14.2.1~102^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F27215%2Fhead;p=ceph.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 (cherry picked from commit 998b1925bd6d19b2b32141b92de66b77027130a0) --- diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index bf4e12407594..37e4c347f5b8 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -12,6 +12,8 @@ * */ +#include +#include #include #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;