Fixed an iterator bug in 'CombinedAuthenticator::authenticate()'.

This patch updates the `loop()` logic within
`CombinedAuthenticatorProcess::authenticate()` to fix a bug
in which an iterator is incremented past the end of its vector.

Review: https://reviews.apache.org/r/58175/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/61fe4732
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/61fe4732
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/61fe4732

Branch: refs/heads/master
Commit: 61fe4732d3d8eeaf9ee10c15314c91ebc4cf333f
Parents: c2ce0cc
Author: Greg Mann <[email protected]>
Authored: Tue Apr 4 10:43:10 2017 -0700
Committer: Anand Mazumdar <[email protected]>
Committed: Tue Apr 4 10:49:00 2017 -0700

----------------------------------------------------------------------
 .../http/combined_authenticator.cpp             | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/61fe4732/src/authentication/http/combined_authenticator.cpp
----------------------------------------------------------------------
diff --git a/src/authentication/http/combined_authenticator.cpp 
b/src/authentication/http/combined_authenticator.cpp
index 2ab6081..51ec882 100644
--- a/src/authentication/http/combined_authenticator.cpp
+++ b/src/authentication/http/combined_authenticator.cpp
@@ -265,7 +265,7 @@ Future<AuthenticationResult> 
CombinedAuthenticatorProcess::authenticate(
     const Request& request)
 {
   // Variables to hold the state of the authentication loop.
-  auto authenticator = authenticators.begin();
+  auto iter = authenticators.begin();
   auto end = authenticators.end();
   // Each pair contains a string representing the scheme of the authenticator
   // and a `Try<AuthenticationResult>` which is used to capture failure 
messages
@@ -277,18 +277,18 @@ Future<AuthenticationResult> 
CombinedAuthenticatorProcess::authenticate(
   // Loop over all installed authenticators.
   return loop(
       self(),
-      [authenticator]() mutable {
-        return authenticator++;
+      [iter, end]() mutable {
+        return iter == end ? Option<Owned<Authenticator>>::none() : *(iter++);
       },
-      [request, results, end, self_](
-          vector<Owned<Authenticator>>::const_iterator authenticator) mutable
+      [request, results, self_](
+          const Option<Owned<Authenticator>>& authenticator) mutable
               -> Future<ControlFlow<AuthenticationResult>> {
         // All authentication attempts have failed. Combine them and return.
-        if (authenticator == end) {
+        if (authenticator.isNone()) {
           return combineFailed(results);
         }
 
-        return authenticator->get()->authenticate(request)
+        return authenticator.get()->authenticate(request)
           .then(defer(
               self_,
               [&results, authenticator](const AuthenticationResult& result)
@@ -301,7 +301,7 @@ Future<AuthenticationResult> 
CombinedAuthenticatorProcess::authenticate(
 
                 if (count != 1) {
                   LOG(WARNING) << "HTTP authenticator for scheme '"
-                               << authenticator->get()->scheme()
+                               << authenticator.get()->scheme()
                                << "' returned a result with " << count
                                << " members set, which is an error";
                   return Continue();
@@ -314,7 +314,7 @@ Future<AuthenticationResult> 
CombinedAuthenticatorProcess::authenticate(
 
                 // Authentication unsuccessful; append the result and continue.
                 results.push_back(make_pair(
-                    authenticator->get()->scheme(),
+                    authenticator.get()->scheme(),
                     result));
                 return Continue();
               }))
@@ -322,7 +322,7 @@ Future<AuthenticationResult> 
CombinedAuthenticatorProcess::authenticate(
               const Future<ControlFlow<AuthenticationResult>>& failedResult)
                   -> ControlFlow<AuthenticationResult> {
             results.push_back(make_pair(
-                authenticator->get()->scheme(),
+                authenticator.get()->scheme(),
                 Error(failedResult.failure())));
             return Continue();
           });

Reply via email to