]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-data-stack - ensure t_push() and t_pop() are balanced in fatal tests
authorPhil Carmody <phil@dovecot.fi>
Wed, 17 Jun 2015 08:42:30 +0000 (11:42 +0300)
committerPhil Carmody <phil@dovecot.fi>
Wed, 17 Jun 2015 08:42:30 +0000 (11:42 +0300)
If the t_pop() unexpectedly succeeds, we won't want to do another one upon
entering the function again.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/test-data-stack.c

index c09f407c4baa2329824e2a9bbf072a238cdcae90..0064c537958f7fb7faf94899b5c290c4d5ffbf4f 100644 (file)
@@ -158,13 +158,13 @@ enum fatal_test_state fatal_data_stack(int stage)
                /* Presume that we need to clean up from the prior test:
                   undo the evil write, then we will be able to t_pop cleanly,
                   and finally we can end the test stanza. */
-               if (things_are_messed_up || undo_ptr == NULL || t_id == 999999999)
+               if (things_are_messed_up || undo_ptr == NULL)
                        return FATAL_TEST_ABORT; /* abort, things are messed up with t_pop */
                *undo_ptr = undo_data;
                undo_ptr = NULL;
                /* t_pop musn't abort, that would cause recursion */
                things_are_messed_up = TRUE;
-               if (t_pop() != t_id)
+               if (t_id != 999999999 && t_pop() != t_id)
                        return FATAL_TEST_ABORT; /* abort, things are messed up with us */
                things_are_messed_up = FALSE;
                t_id = 999999999;
@@ -206,6 +206,7 @@ enum fatal_test_state fatal_data_stack(int stage)
                *undo_ptr = '*';
                /* t_pop will now fail */
                (void)t_pop();
+               t_id = 999999999; /* We're FUBAR, mustn't pop next entry */
                return FATAL_TEST_FAILURE;
        }
 
@@ -218,6 +219,7 @@ enum fatal_test_state fatal_data_stack(int stage)
                *undo_ptr = '*';
                /* t_pop will now fail */
                (void)t_pop();
+               t_id = 999999999; /* We're FUBAR, mustn't pop next entry */
                return FATAL_TEST_FAILURE;
        }