]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
Fixed 2 potential buffer overflows in SearchInfostring
[xonotic/darkplaces.git] / common.c
index b3378939aef1301adfbc69cf630f2e96b39c5879..4ff60bb9d4c9fd97bb5ca0acd82315c5f84efe1a 100644 (file)
--- a/common.c
+++ b/common.c
@@ -219,7 +219,7 @@ void MSG_WriteString (sizebuf_t *sb, const char *s)
                SZ_Write (sb, s, strlen(s)+1);
 }
 
-// used by server (always latest dpprotocol)
+// used by server (always latest PROTOCOL_DARKPLACES)
 void MSG_WriteDPCoord (sizebuf_t *sb, float f)
 {
        if (f >= 0)
@@ -353,7 +353,7 @@ int MSG_ReadBytes (int numbytes, unsigned char *out)
        return l;
 }
 
-// used by server (always latest dpprotocol)
+// used by server (always latest PROTOCOL_DARKPLACES)
 float MSG_ReadDPCoord (void)
 {
        return (signed short) MSG_ReadLittleShort();
@@ -362,9 +362,9 @@ float MSG_ReadDPCoord (void)
 // used by client
 float MSG_ReadCoord (void)
 {
-       if (dpprotocol == DPPROTOCOL_VERSION2 || dpprotocol == DPPROTOCOL_VERSION3 || dpprotocol == DPPROTOCOL_VERSION4)
+       if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
                return (signed short) MSG_ReadLittleShort();
-       else if (dpprotocol == DPPROTOCOL_VERSION1)
+       else if (cl.protocol == PROTOCOL_DARKPLACES1)
                return MSG_ReadLittleFloat();
        else
                return MSG_ReadLittleShort() * (1.0f/8.0f);
@@ -694,6 +694,8 @@ void COM_InitGameType (void)
                gamemode = GAME_TEU;
        else if (strstr(name, "battlemech"))
                gamemode = GAME_BATTLEMECH;
+       else if (strstr(name, "zymotic"))
+               gamemode = GAME_ZYMOTIC;
        else
                gamemode = GAME_NORMAL;
 
@@ -715,6 +717,8 @@ void COM_InitGameType (void)
                gamemode = GAME_TEU;
        else if (COM_CheckParm ("-battlemech"))
                gamemode = GAME_BATTLEMECH;
+       else if (COM_CheckParm ("-zymotic"))
+               gamemode = GAME_ZYMOTIC;
 
        switch(gamemode)
        {
@@ -748,11 +752,15 @@ void COM_InitGameType (void)
                break;
        case GAME_TEU:
                gamename = "TheEvilUnleashed";
-               gamedirname = "teu";
+               gamedirname = "baseteu";
                break;
        case GAME_BATTLEMECH:
                gamename = "Battlemech";
-               gamedirname = "battlemech";
+               gamedirname = "base";
+               break;
+       case GAME_ZYMOTIC:
+               gamename = "Zymotic";
+               gamedirname = "data";
                break;
        default:
                Sys_Error("COM_InitGameType: unknown gamemode %i\n", gamemode);
@@ -890,7 +898,7 @@ char *SearchInfostring(const char *infostring, const char *key)
 
                        if (c == '\0')
                                return NULL;
-                       if (c == '\\')
+                       if (c == '\\' || key_ind == sizeof (crt_key) - 1)
                        {
                                crt_key[key_ind] = '\0';
                                break;
@@ -906,7 +914,7 @@ char *SearchInfostring(const char *infostring, const char *key)
                        {
                                c = *infostring++;
 
-                               if (c == '\0' || c == '\\')
+                               if (c == '\0' || c == '\\' || value_ind == sizeof (value) - 1)
                                {
                                        value[value_ind] = '\0';
                                        return value;