]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Heap-allocate sessionid cvar's string to avoid stack corruption
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Jun 2020 14:49:55 +0000 (14:49 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Jun 2020 14:49:55 +0000 (14:49 +0000)
Previously it was trying to shove the address of a local variable, which
is bad.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12633 d7cf8633-e32d-0410-b094-e92efae38249

host.c

diff --git a/host.c b/host.c
index 9a3d6ace0e82e46c5b88912b6933fc2be41d54d2..ae985c505426bc28c613ea6f21a82cd118258822 100644 (file)
--- a/host.c
+++ b/host.c
@@ -1112,17 +1112,21 @@ static qboolean locksession_run = false;
 static void Host_InitSession(void)
 {
        int i;
+       char *buf;
        Cvar_RegisterVariable(&sessionid);
        Cvar_RegisterVariable(&locksession);
 
        // load the session ID into the read-only cvar
        if ((i = COM_CheckParm("-sessionid")) && (i + 1 < com_argc))
        {
-               char vabuf[1024];
                if(com_argv[i+1][0] == '.')
                        Cvar_SetQuick(&sessionid, com_argv[i+1]);
                else
-                       Cvar_SetQuick(&sessionid, va(vabuf, sizeof(vabuf), ".%s", com_argv[i+1]));
+               {
+                       buf = (char *)Z_Malloc(strlen(com_argv[i+1]+2));
+                       dpsnprintf(buf, sizeof(buf), ".%s", com_argv[i+1]);
+                       Cvar_SetQuick(&sessionid, buf);
+               }
        }
 }
 void Host_LockSession(void)