fix issues with sound freeslotting
this "works" with a skinlimit of 255 but would cause hard to debug crashes with raised skinlimits and was generally really unsafe and could cause soundnames to not be null terminated aswell as buffer overflows from blind strcpy the sprintf fix is from Indev originally for neptune NOTE: if the skinlimit is ever raised above 1024 then freeslotnames NEEDS to be atleast one byte bigger to not truncuate stuff NOTE2: pretty sure localskins are fucked if any are loaded in servers with 255 skins loaded, but i dont care atm
This commit is contained in:
1 parent
df3a64339c
commit
9692484d2e
2 files changed
+14
-11
No files matched your search
+12
-11
@@ -972,7 +972,7 @@ sfxinfo_t S_sfx[NUMSFX] =
|
||||
// initialized to NULL
|
||||
};
|
||||
|
||||
char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][7] = {};
|
||||
static char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][MAXSOUNDNAME] = {};
|
||||
|
||||
// Prepare free sfx slots to add sfx at run time
|
||||
void S_InitRuntimeSounds(void)
|
||||
@@ -985,16 +985,13 @@ void S_InitRuntimeSounds(void)
|
||||
{
|
||||
value = (i+1) - sfx_freeslot0;
|
||||
|
||||
if (value < 10)
|
||||
sprintf(soundname, "fre00%d", value);
|
||||
else if (value < 100)
|
||||
sprintf(soundname, "fre0%d", value);
|
||||
else if (value < 1000)
|
||||
sprintf(soundname, "fre%d", value);
|
||||
else
|
||||
sprintf(soundname, "fr%d", value);
|
||||
sprintf(soundname, "fr%04x", value);
|
||||
|
||||
strcpy(freeslotnames[value-1], soundname);
|
||||
// this might happen when raising skinlimit
|
||||
I_Assert(strlen(soundname) < MAXSOUNDNAME);
|
||||
|
||||
strncpy(freeslotnames[value-1], soundname, MAXSOUNDNAME-1);
|
||||
freeslotnames[value-1][MAXSOUNDNAME-1] = '\0';
|
||||
|
||||
S_sfx[i].name = freeslotnames[value-1];
|
||||
S_sfx[i].singularity = false;
|
||||
@@ -1024,7 +1021,11 @@ sfxenum_t S_AddSoundFx(const char *name, boolean singular, INT32 flags, boolean
|
||||
{
|
||||
if (!S_sfx[i].priority)
|
||||
{
|
||||
strncpy(freeslotnames[i-sfx_freeslot0], name, 6);
|
||||
I_Assert(strlen(name) < MAXSOUNDNAME);
|
||||
|
||||
strncpy(freeslotnames[i - sfx_freeslot0], name, MAXSOUNDNAME-1);
|
||||
freeslotnames[i - sfx_freeslot0][MAXSOUNDNAME-1] = '\0';
|
||||
|
||||
S_sfx[i].singularity = singular;
|
||||
S_sfx[i].priority = 60;
|
||||
S_sfx[i].pitch = flags;
|
||||
|
||||
@@ -59,6 +59,8 @@ typedef enum
|
||||
#define NUMSFXFREESLOTS 1600 // Matches SOC Editor.
|
||||
#define NUMSKINSFXSLOTS (MAXSKINS*NUMSKINSOUNDS)
|
||||
|
||||
#define MAXSOUNDNAME 7
|
||||
|
||||
//
|
||||
// SoundFX struct.
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user