- Add input sanitising to various sound playing functions called from MODs.

This fixes https://bugzilla.icculus.org/show_bug.cgi?id=2836
- Make searching through the knownSfx array a bit more efficient.
This commit is contained in:
Thilo Schulz 2006-11-25 13:35:23 +00:00
parent 3b046464e3
commit 26cf8f2987

View file

@ -137,8 +137,12 @@ static sfxHandle_t S_AL_BufferFindFree( void )
{ {
// Got one // Got one
if(knownSfx[i].filename[0] == '\0') if(knownSfx[i].filename[0] == '\0')
{
if(i > numSfx)
numSfx = i + 1;
return i; return i;
} }
}
// Shit... // Shit...
Com_Error(ERR_FATAL, "S_AL_BufferFindFree: No free sound handles"); Com_Error(ERR_FATAL, "S_AL_BufferFindFree: No free sound handles");
@ -158,7 +162,7 @@ static sfxHandle_t S_AL_BufferFind(const char *filename)
sfxHandle_t sfx = -1; sfxHandle_t sfx = -1;
int i; int i;
for(i = 0; i < MAX_SFX; i++) for(i = 0; i < numSfx; i++)
{ {
if(!Q_stricmp(knownSfx[i].filename, filename)) if(!Q_stricmp(knownSfx[i].filename, filename))
{ {
@ -233,7 +237,7 @@ static qboolean S_AL_BufferEvict( void )
int i, oldestBuffer = -1; int i, oldestBuffer = -1;
int oldestTime = Sys_Milliseconds( ); int oldestTime = Sys_Milliseconds( );
for( i = 0; i < MAX_SFX; i++ ) for( i = 0; i < numSfx; i++ )
{ {
if( !knownSfx[ i ].filename[ 0 ] ) if( !knownSfx[ i ].filename[ 0 ] )
continue; continue;
@ -407,7 +411,7 @@ void S_AL_BufferShutdown( void )
knownSfx[default_sfx].isLocked = qfalse; knownSfx[default_sfx].isLocked = qfalse;
// Free all used effects // Free all used effects
for(i = 0; i < MAX_SFX; i++) for(i = 0; i < numSfx; i++)
S_AL_BufferUnload(i); S_AL_BufferUnload(i);
// Clear the tables // Clear the tables
@ -878,6 +882,27 @@ void S_AL_UpdateEntityPosition( int entityNum, const vec3_t origin )
VectorCopy( origin, entityList[entityNum].origin ); VectorCopy( origin, entityList[entityNum].origin );
} }
/*
=================
S_AL_CheckInput
Check whether input values from mods are out of range.
Necessary for i.g. Western Quake3 mod which is buggy.
=================
*/
static qboolean S_AL_CheckInput(int entityNum, sfxHandle_t sfx)
{
if (entityNum < 0 || entityNum > MAX_GENTITIES)
Com_Error(ERR_DROP, "S_StartSound: bad entitynum %i", entityNum);
if (sfx < 0 || sfx >= numSfx)
{
Com_Printf(S_COLOR_RED, "ERROR: S_AL_CheckInput: handle %i out of range\n", sfx);
return qtrue;
}
return qfalse;
}
/* /*
================= =================
S_AL_StartLocalSound S_AL_StartLocalSound
@ -888,6 +913,9 @@ Play a local (non-spatialized) sound effect
static static
void S_AL_StartLocalSound(sfxHandle_t sfx, int channel) void S_AL_StartLocalSound(sfxHandle_t sfx, int channel)
{ {
if(S_AL_CheckInput(0, sfx))
return;
// Try to grab a source // Try to grab a source
srcHandle_t src = S_AL_SrcAlloc(SRCPRI_LOCAL, -1, channel); srcHandle_t src = S_AL_SrcAlloc(SRCPRI_LOCAL, -1, channel);
if(src == -1) if(src == -1)
@ -912,6 +940,9 @@ void S_AL_StartSound( vec3_t origin, int entnum, int entchannel, sfxHandle_t sfx
{ {
vec3_t sorigin; vec3_t sorigin;
if(S_AL_CheckInput(origin ? 0 : entnum, sfx))
return;
// Try to grab a source // Try to grab a source
srcHandle_t src = S_AL_SrcAlloc(SRCPRI_ONESHOT, entnum, entchannel); srcHandle_t src = S_AL_SrcAlloc(SRCPRI_ONESHOT, entnum, entchannel);
if(src == -1) if(src == -1)
@ -1038,6 +1069,9 @@ S_AL_AddLoopingSound
static static
void S_AL_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx ) void S_AL_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx )
{ {
if(S_AL_CheckInput(entityNum, sfx))
return;
S_AL_SanitiseVector( (vec_t *)origin ); S_AL_SanitiseVector( (vec_t *)origin );
S_AL_SanitiseVector( (vec_t *)velocity ); S_AL_SanitiseVector( (vec_t *)velocity );
S_AL_SrcLoop(SRCPRI_ENTITY, sfx, origin, velocity, entityNum); S_AL_SrcLoop(SRCPRI_ENTITY, sfx, origin, velocity, entityNum);
@ -1051,6 +1085,9 @@ S_AL_AddRealLoopingSound
static static
void S_AL_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx ) void S_AL_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx )
{ {
if(S_AL_CheckInput(entityNum, sfx))
return;
S_AL_SanitiseVector( (vec_t *)origin ); S_AL_SanitiseVector( (vec_t *)origin );
S_AL_SanitiseVector( (vec_t *)velocity ); S_AL_SanitiseVector( (vec_t *)velocity );