More strcpy -> strlcpy and sprintf -> snprintf
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 30 Sep 2003 15:07:55 +0000 (15:07 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 30 Sep 2003 15:07:55 +0000 (15:07 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3519 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
netconn.c
sv_main.c
zone.c

index 9a7ad21..ee94244 100644 (file)
@@ -230,14 +230,14 @@ void CL_ParseEntityLump(char *entdata)
                if (com_token[0] == '}')
                        break; // end of worldspawn
                if (com_token[0] == '_')
-                       strcpy(key, com_token + 1);
+                       strlcpy (key, com_token + 1, sizeof (key));
                else
-                       strcpy(key, com_token);
+                       strlcpy (key, com_token, sizeof (key));
                while (key[strlen(key)-1] == ' ') // remove trailing spaces
                        key[strlen(key)-1] = 0;
                if (!COM_ParseToken(&data, false))
                        return; // error
-               strcpy(value, com_token);
+               strlcpy (value, com_token, sizeof (value));
                if (!strcmp("sky", key))
                        R_SetSkyBox(value);
                else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
@@ -382,7 +382,7 @@ void CL_ParseServerInfo (void)
                        Host_Error ("Server sent too many model precaches\n");
                if (strlen(str) >= MAX_QPATH)
                        Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
-               strcpy(parse_model_precache[nummodels], str);
+               strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
        }
        // parse sound precache list
        for (numsounds=1 ; ; numsounds++)
@@ -394,7 +394,7 @@ void CL_ParseServerInfo (void)
                        Host_Error("Server sent too many sound precaches\n");
                if (strlen(str) >= MAX_QPATH)
                        Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
-               strcpy(parse_sound_precache[numsounds], str);
+               strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
        }
 
        // touch all of the precached models that are still loaded so we can free
@@ -1457,7 +1457,7 @@ void CL_ParseServerMessage(void)
                        {
                                char description[32*64], temp[64];
                                int count;
-                               strcpy(description, "packet dump: ");
+                               strcpy (description, "packet dump: ");
                                i = cmdcount - 32;
                                if (i < 0)
                                        i = 0;
index c37a42b..32e2f89 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -765,7 +765,7 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                Con_Printf("received server list...\n");
                        while (length >= 7 && data[0] == '\\' && (data[1] != 0xFF || data[2] != 0xFF || data[3] != 0xFF || data[4] != 0xFF) && data[5] * 256 + data[6] != 0)
                        {
-                               sprintf(ipstring, "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]);
+                               snprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]);
                                if (developer.integer)
                                        Con_Printf("Requesting info from server %s\n", ipstring);
                                LHNETADDRESS_FromString(&svaddress, ipstring, 0);
@@ -793,7 +793,7 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                }
                                memset(&hostcache[n], 0, sizeof(hostcache[n]));
                                // store the data the engine cares about (address and ping)
-                               strcpy(hostcache[n].cname, ipstring);
+                               strlcpy (hostcache[n].cname, ipstring, sizeof (hostcache[n].cname));
                                hostcache[n].ping = 100000;
                                hostcache[n].querytime = realtime;
                                // build description strings for the things users care about
@@ -891,8 +891,8 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                {
                                        hostCacheCount++;
                                        memset(&hostcache[n], 0, sizeof(hostcache[n]));
-                                       strcpy(hostcache[n].name, MSG_ReadString());
-                                       strcpy(hostcache[n].map, MSG_ReadString());
+                                       strlcpy (hostcache[n].name, MSG_ReadString(), sizeof (hostcache[n].name));
+                                       strlcpy (hostcache[n].map, MSG_ReadString(), sizeof (hostcache[n].map));
                                        hostcache[n].users = MSG_ReadByte();
                                        hostcache[n].maxusers = MSG_ReadByte();
                                        c = MSG_ReadByte();
@@ -902,7 +902,7 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                                strcpy(hostcache[n].name, "*");
                                                strlcat (hostcache[n].name, hostcache[n].cname, sizeof(hostcache[n].name));
                                        }
-                                       strcpy(hostcache[n].cname, cname);
+                                       strlcpy (hostcache[n].cname, cname, sizeof (hostcache[n].cname));
                                }
                        }
                        break;
@@ -942,7 +942,7 @@ void NetConn_ClientFrame(void)
                {
                        cls.connect_trying = false;
                        if (m_state == m_slist)
-                               strcpy(m_return_reason, "Connect: Failed");
+                               strcpy (m_return_reason, "Connect: Failed");
                        else
                                Con_Printf("Connect failed\n");
                        return;
@@ -950,14 +950,14 @@ void NetConn_ClientFrame(void)
                if (cls.connect_nextsendtime)
                {
                        if (m_state == m_slist)
-                               strcpy(m_return_reason, "Connect: Still trying");
+                               strcpy (m_return_reason, "Connect: Still trying");
                        else
                                Con_Printf("Still trying...\n");
                }
                else
                {
                        if (m_state == m_slist)
-                               strcpy(m_return_reason, "Connect: Trying");
+                               strcpy (m_return_reason, "Connect: Trying");
                        else
                                Con_Printf("Trying...\n");
                }
@@ -1256,7 +1256,7 @@ int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                                                {
                                                                        // connect to the client
                                                                        // everything is allocated, just fill in the details
-                                                                       strcpy(conn->address, addressstring2);
+                                                                       strlcpy (conn->address, addressstring2, sizeof (conn->address));
                                                                        if (developer.integer)
                                                                                Con_Printf("Datagram_ParseConnectionless: sending CCREP_ACCEPT to %s.\n", addressstring2);
                                                                        // send back the info about the server connection
index ac63682..8332e73 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -254,7 +254,7 @@ void SV_SendServerinfo (client_t *client)
        client->entitydatabase4 = EntityFrame4_AllocDatabase(sv_clients_mempool);
 
        MSG_WriteByte (&client->message, svc_print);
-       sprintf (message, "\002\nServer: %s build %s (progs %i crc)", gamename, buildstring, pr_crc);
+       snprintf (message, sizeof (message), "\002\nServer: %s build %s (progs %i crc)", gamename, buildstring, pr_crc);
        MSG_WriteString (&client->message,message);
 
        MSG_WriteByte (&client->message, svc_serverinfo);
@@ -1775,7 +1775,7 @@ void SV_SpawnServer (const char *server)
 
        memset (&sv, 0, sizeof(sv));
 
-       strcpy (sv.name, server);
+       strlcpy (sv.name, server, sizeof (sv.name));
 
 // load progs to get entity field count
        PR_LoadProgs ();
@@ -1824,8 +1824,8 @@ void SV_SpawnServer (const char *server)
 
        Mod_ClearUsed();
 
-       strcpy (sv.name, server);
-       sprintf (sv.modelname,"maps/%s.bsp", server);
+       strlcpy (sv.name, server, sizeof (sv.name));
+       snprintf (sv.modelname, sizeof (sv.modelname), "maps/%s.bsp", server);
        sv.worldmodel = Mod_ForName(sv.modelname, false, true, true);
        if (!sv.worldmodel)
        {
diff --git a/zone.c b/zone.c
index a68c136..e20b420 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -218,7 +218,7 @@ mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline)
        pool->chain = NULL;
        pool->totalsize = 0;
        pool->realsize = sizeof(mempool_t);
-       strcpy(pool->name, name);
+       strlcpy (pool->name, name, sizeof (pool->name));
        pool->next = poolchain;
        poolchain = pool;
        return pool;