]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
when the engine is compiled with -DFILLALLCVARSWITHRUBBISH, there is an extra console...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Jun 2009 13:41:00 +0000 (13:41 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Jun 2009 13:41:00 +0000 (13:41 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9022 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
cvar.c
cvar.h

diff --git a/cmd.c b/cmd.c
index b0d6a9e14f9b038238aa5e27b387afc9dd60d6fd..fad9aa4d5b4a51991be26e8ca67aa074cac2d936 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -1145,6 +1145,9 @@ void Cmd_Init_Commands (void)
        Cmd_AddCommand ("wait", Cmd_Wait_f, "make script execution wait for next rendered frame");
        Cmd_AddCommand ("set", Cvar_Set_f, "create or change the value of a console variable");
        Cmd_AddCommand ("seta", Cvar_SetA_f, "create or change the value of a console variable that will be saved to config.cfg");
+#ifdef FILLALLCVARSWITHRUBBISH
+       Cmd_AddCommand ("fillallcvarswithrubbish", Cvar_FillAll_f, "fill all cvars with a specified number of characters to provoke buffer overruns");
+#endif /* FILLALLCVARSWITHRUBBISH */
 
        // 2000-01-09 CmdList, CvarList commands By Matthias "Maddes" Buecher
        // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
diff --git a/cvar.c b/cvar.c
index 2aa3e9437ab94a6f97ea6c9ce9fc84fafb17c2f6..94fd37fc3e7f9105e388a5bea51a16fa06da8a6e 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -762,4 +762,39 @@ void Cvar_SetA_f (void)
        Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
 }
 
-
+#ifdef FILLALLCVARSWITHRUBBISH
+void Cvar_FillAll_f()
+{
+       char *buf, *p, *q;
+       int n, i;
+       cvar_t *var;
+       qboolean verify;
+       if(Cmd_Argc() != 2)
+       {
+               Con_Printf("Usage: %s length to plant rubbish\n", Cmd_Argv(0));
+               Con_Printf("Usage: %s -length to verify that the rubbish is still there\n", Cmd_Argv(0));
+               return;
+       }
+       n = atoi(Cmd_Argv(1));
+       verify = (n < 0);
+       if(verify)
+               n = -n;
+       buf = Z_Malloc(n + 1);
+       buf[n] = 0;
+       for(var = cvar_vars; var; var = var->next)
+       {
+               for(i = 0, p = buf, q = var->name; i < n; ++i)
+               {
+                       *p++ = *q++;
+                       if(!*q)
+                               q = var->name;
+               }
+               if(verify && strcmp(var->string, buf))
+               {
+                       Con_Printf("\n%s does not contain the right rubbish, either this is the first run or a possible overrun was detected, or something changed it intentionally; it DOES contain: %s\n", var->name, var->string);
+               }
+               Cvar_SetQuick(var, buf);
+       }
+       Z_Free(buf);
+}
+#endif /* FILLALLCVARSWITHRUBBISH */
diff --git a/cvar.h b/cvar.h
index 70f85fc92a060917c0a35e9e3b0e9b9c3de04819..fa7065971020c652cb6ac97c607fa82f3bb8cf26 100644 (file)
--- a/cvar.h
+++ b/cvar.h
@@ -209,5 +209,9 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *ne
 extern char *cvar_dummy_description; // ALWAYS the same pointer
 extern cvar_t *cvar_vars; // used to list all cvars
 
+#ifdef FILLALLCVARSWITHRUBBISH
+void Cvar_FillAll_f();
+#endif /* FILLALLCVARSWITHRUBBISH */
+
 #endif