]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
PRVM: disallow changing read-only cvars
authorbones_was_here <bones_was_here@xonotic.au>
Thu, 18 Jan 2024 05:43:15 +0000 (15:43 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sun, 21 Jan 2024 07:00:46 +0000 (17:00 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
prvm_cmds.c

index 379b7d362bbebce76ad2417b09207424b365b504..5a86622243f64fe7fafc0208701632f5d36eb095 100644 (file)
@@ -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);
 }
 
 /*