From 998b1925bd6d19b2b32141b92de66b77027130a0 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 --- 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 2c36868c13c56..1ce68eb19a611 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; -- 2.39.5