From 19495cd75a6f0d01c8b527fbeab4eeb8380909eb Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 27 Mar 2019 00:02:01 +0800 Subject: [PATCH] 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) --- src/mon/MonClient.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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; -- 2.47.3