]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
Fix NULL crash in QW_CL_RequestNextDownload without connection.
[xonotic/darkplaces.git] / cl_parse.c
index e8e17f1cb980309bd6c85615dcdc5cad01e1af07..26a0ed1120a4891854fdf6a8fcb68a80bd32adef 100644 (file)
@@ -227,7 +227,7 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
                        attenuation = MSG_ReadByte(&cl_message) / 64.0;
                else
                        attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
-       
+
                speed = 1.0f;
 
                ent = (channel>>3)&1023;
@@ -276,7 +276,7 @@ static void CL_ParseStartSoundPacket(int largesoundindex)
 
        MSG_ReadVector(&cl_message, pos, cls.protocol);
 
-       if (sound_num >= MAX_SOUNDS)
+       if (sound_num < 0 || sound_num >= MAX_SOUNDS)
        {
                Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
                return;
@@ -586,6 +586,12 @@ static void QW_CL_RequestNextDownload(void)
        // clear name of file that just finished
        cls.qw_downloadname[0] = 0;
 
+       // skip the download fragment if playing a demo
+       if (!cls.netcon)
+       {
+               return;
+       }
+
        switch (cls.qw_downloadtype)
        {
        case dl_single:
@@ -1039,7 +1045,7 @@ static void QW_CL_ParseNails(void)
        {
                for (j = 0;j < 6;j++)
                        bits[j] = MSG_ReadByte(&cl_message);
-               if (cl.qw_num_nails > 255)
+               if (cl.qw_num_nails >= 255)
                        continue;
                v = cl.qw_nails[cl.qw_num_nails++];
                v[0] = ( ( bits[0] + ((bits[1]&15)<<8) ) <<1) - 4096;
@@ -2305,6 +2311,13 @@ static void CL_ParseStaticSound (int large)
                sound_num = (unsigned short) MSG_ReadShort(&cl_message);
        else
                sound_num = MSG_ReadByte(&cl_message);
+
+       if (sound_num < 0 || sound_num >= MAX_SOUNDS)
+       {
+               Con_Printf("CL_ParseStaticSound: sound_num(%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
+               return;
+       }
+
        vol = MSG_ReadByte(&cl_message);
        atten = MSG_ReadByte(&cl_message);