From 135e5191fc7edf867bccfb8f72e205e956c0e93f Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Mon, 25 Sep 2023 19:30:33 +1000 Subject: [PATCH] cbuf: catch runaway command loops, respects -norunaway cmdline arg Prevents DP from spinlocking permanently. Signed-off-by: bones_was_here --- cmd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd.c b/cmd.c index 8a301066..98e4ca35 100644 --- 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; + } } } -- 2.39.2