]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3050] Always clear "skip" flag before calling any callouts on a hook
authorStephen Morris <stephen@isc.org>
Wed, 24 Jul 2013 12:53:50 +0000 (13:53 +0100)
committerStephen Morris <stephen@isc.org>
Wed, 24 Jul 2013 12:53:50 +0000 (13:53 +0100)
src/lib/hooks/callout_manager.cc
src/lib/hooks/tests/handles_unittest.cc

index 5a2126a9562409d6c3939f91aa9640dd6c0f23e4..df27f45c4b8d74d51bf762bfbf2bfe557fec1ef6 100644 (file)
@@ -113,13 +113,15 @@ CalloutManager::calloutsPresent(int hook_index) const {
 void
 CalloutManager::callCallouts(int hook_index, CalloutHandle& callout_handle) {
 
+    // Clear the "skip" flag so we don't carry state from a previous call.
+    // This is done regardless of whether callouts are present to avoid passing
+    // any state from the previous call of callCallouts().
+    callout_handle.setSkip(false);
+
     // Only initialize and iterate if there are callouts present.  This check
     // also catches the case of an invalid index.
     if (calloutsPresent(hook_index)) {
 
-        // Clear the "skip" flag so we don't carry state from a previous call.
-        callout_handle.setSkip(false);
-
         // Set the current hook index.  This is used should a callout wish to
         // determine to what hook it is attached.
         current_hook_ = hook_index;
index e5364bcbe6af5361a75a5941e9f6e0d90f4c510b..c19dff2773732c71d5779f22c7ed737880843dee 100644 (file)
@@ -841,6 +841,24 @@ TEST_F(HandlesTest, ReturnSkipClear) {
     EXPECT_FALSE(callout_handle.getSkip());
 }
 
+// Check that the skip flag is cleared when callouts are called - even if
+// there are no callouts.
+
+TEST_F(HandlesTest, NoCalloutsSkipTest) {
+    // Note - no callouts are registered on any hook.
+    CalloutHandle callout_handle(getCalloutManager());
+
+    // Clear the skip flag and call a hook with no callouts.
+    callout_handle.setSkip(false);
+    getCalloutManager()->callCallouts(alpha_index_, callout_handle);
+    EXPECT_FALSE(callout_handle.getSkip());
+
+    // Set the skip flag and call a hook with no callouts.
+    callout_handle.setSkip(true);
+    getCalloutManager()->callCallouts(alpha_index_, callout_handle);
+    EXPECT_FALSE(callout_handle.getSkip());
+}
+
 // The next set of callouts do a similar thing to the above "skip" tests,
 // but alter the value of a string argument.  This is for testing that the
 // a callout is able to change an argument and return it to the caller.