]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cbuf: catch runaway command loops, respects -norunaway cmdline arg
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 25 Sep 2023 09:30:33 +0000 (19:30 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 26 Sep 2023 04:40:26 +0000 (14:40 +1000)
Prevents DP from spinlocking permanently.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cmd.c

diff --git a/cmd.c b/cmd.c
index 8a301066fd644556bacd6cc45784eaee9651ebc5..98e4ca35478bb8b6fd95bc7f8d72e89b8ae4bca3 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -386,12 +386,14 @@ static void Cbuf_Execute_Deferred (cmd_buf_t *cbuf)
 Cbuf_Execute
 ============
 */
+extern qbool prvm_runawaycheck;
 static qbool Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias );
 void Cbuf_Execute (cmd_buf_t *cbuf)
 {
        cmd_input_t *current;
        char preprocessed[MAX_INPUTLINE];
        char *firstchar;
+       unsigned int i = 0;
 
        // LadyHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes
        cbuf->tokenizebufferpos = 0;
@@ -443,6 +445,16 @@ void Cbuf_Execute (cmd_buf_t *cbuf)
                        cbuf->wait = false;
                        break;
                }
+
+               if (++i == 1000000 && prvm_runawaycheck)
+               {
+                       Con_Printf(CON_WARN "Cbuf_Execute: runaway loop counter hit limit of %d commands, clearing command buffers!\n", i);
+                       while (!List_Is_Empty(&cbuf->start))
+                               List_Move_Tail(cbuf->start.next, &cbuf->free);
+                       while (!List_Is_Empty(&cbuf->deferred))
+                               List_Move_Tail(cbuf->deferred.next, &cbuf->free);
+                       cbuf->size = 0;
+               }
        }
 }