From 1df5f9fe139f272669658a720bc9a3360a58789d Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Thu, 18 Jan 2024 15:43:15 +1000 Subject: [PATCH] PRVM: disallow changing read-only cvars Signed-off-by: bones_was_here --- prvm_cmds.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/prvm_cmds.c b/prvm_cmds.c index 379b7d36..5a866222 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -806,12 +806,25 @@ void cvar_set (string,string, ...) void VM_cvar_set(prvm_prog_t *prog) { const char *name; - char string[VM_STRINGTEMP_LENGTH]; + char value[VM_STRINGTEMP_LENGTH]; + cvar_t *cvar; + VM_SAFEPARMCOUNTRANGE(2,8,VM_cvar_set); - VM_VarString(prog, 1, string, sizeof(string)); name = PRVM_G_STRING(OFS_PARM0); VM_CheckEmptyString(prog, name); - Cvar_Set(prog->console_cmd->cvars, name, string); + cvar = Cvar_FindVar(prog->console_cmd->cvars, name, prog->console_cmd->cvars_flagsmask); + if (!cvar) + { + VM_Warning(prog, "VM_cvar_set: variable %s not found\n", name); + return; + } + if (cvar->flags & CF_READONLY) + { + VM_Warning(prog, "VM_cvar_set: variable %s is read-only\n", cvar->name); + return; + } + VM_VarString(prog, 1, value, sizeof(value)); + Cvar_SetQuick(cvar, value); } /* -- 2.39.2