]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add maximum instruction count for failure testing
authorAlan T. DeKok <aland@freeradius.org>
Mon, 17 Oct 2022 19:03:20 +0000 (15:03 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 17 Oct 2022 20:15:26 +0000 (16:15 -0400)
src/lib/server/request.h
src/lib/unlang/interpret.c
src/lib/unlang/interpret_synchronous.c

index fbc63f686df8dbf2ee06772e5c489917a04cfe5e..8461a0923c05ddda722ebadaba935884e30a8522 100644 (file)
@@ -156,6 +156,10 @@ struct request_s {
 #ifndef NDEBUG
        uint32_t                magic;          //!< Magic number used to detect memory corruption,
                                                //!< or request structs that have not been properly initialised.
+
+       uint64_t                ins_count;      //!< count of instructions we've ran
+       uint64_t                ins_max;        //!< max instruction to bail out at
+
 #endif
        void                    *stack;         //!< unlang interpreter stack.
 
index 15bea9e69687f836bc1dc61196dfeff2740d25e8..1309194e0c5dac539c65d0a627426b3840647df7 100644 (file)
@@ -457,6 +457,20 @@ unlang_frame_action_t frame_eval(request_t *request, unlang_stack_frame_t *frame
                        yielded_clear(frame);
                }
 
+#ifndef NDEBUG
+               /*
+                *      Failure testing!
+                */
+               if (request->ins_max && (request->master_state != REQUEST_STOP_PROCESSING)) {
+                       request->ins_count++;
+
+                       if (request->ins_count >= request->ins_max) {
+                               request->master_state = REQUEST_STOP_PROCESSING;
+                               RERROR("Failing request due to maximum instruction count %" PRIu64, request->ins_max);
+                       }
+               }
+#endif
+
                /*
                 *      unlang_interpret_signal() takes care of
                 *      marking the requests as STOP on a CANCEL
index 601270803921e058edca2af27750dac926e2c89c..94e89238ab337238f1f9a4e3f6efa8d4fed7ce53 100644 (file)
@@ -50,21 +50,23 @@ static void _request_init_internal(request_t *request, void *uctx)
  */
 static void _request_done_external(request_t *request, UNUSED rlm_rcode_t rcode, UNUSED void *uctx)
 {
-       /*
-        *      If we're running a real request, then the final
-        *      indentation MUST be zero.  Otherwise we skipped
-        *      something!
-        *
-        *      Also check that the request is NOT marked as
-        *      "yielded", but is in fact done.
-        *
-        *      @todo - check that the stack is at frame 0, otherwise
-        *      more things have gone wrong.
-        */
-       fr_assert_msg(request->parent || (request->log.unlang_indent == 0),
-                     "Request %s bad log indentation - expected 0 got %u", request->name, request->log.unlang_indent);
-       fr_assert_msg(!unlang_interpret_is_resumable(request),
-                     "Request %s is marked as yielded at end of processing", request->name);
+       if (request->master_state != REQUEST_STOP_PROCESSING) {
+               /*
+                *      If we're running a real request, then the final
+                *      indentation MUST be zero.  Otherwise we skipped
+                *      something!
+                *
+                *      Also check that the request is NOT marked as
+                *      "yielded", but is in fact done.
+                *
+                *      @todo - check that the stack is at frame 0, otherwise
+                *      more things have gone wrong.
+                */
+               fr_assert_msg(request->parent || (request->log.unlang_indent == 0),
+                             "Request %s bad log indentation - expected 0 got %u", request->name, request->log.unlang_indent);
+               fr_assert_msg(!unlang_interpret_is_resumable(request),
+                             "Request %s is marked as yielded at end of processing", request->name);
+       }
 
        RDEBUG3("Synchronous done external request");
 }