From 64ef03428d72eb204f5195c0b9c714db1123fdb0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 7 Jan 2022 00:16:30 +0100 Subject: [PATCH] - added proper range check to the main sound playing function. We got a report where this crashed on a bad sound index. --- src/common/audio/sound/s_sound.cpp | 2 +- src/sound/s_advsound.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index 74393dfddb..cdd0361c5f 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -388,7 +388,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source, FVector3 pos, vel; FRolloffInfo *rolloff; - if (sound_id <= 0 || volume <= 0 || nosfx || !SoundEnabled() || blockNewSounds) + if (sound_id <= 0 || volume <= 0 || nosfx || !SoundEnabled() || blockNewSounds || (unsigned)sound_id >= S_sfx.Size()) return NULL; // prevent crashes. diff --git a/src/sound/s_advsound.cpp b/src/sound/s_advsound.cpp index 7d37c99521..f508c187f4 100644 --- a/src/sound/s_advsound.cpp +++ b/src/sound/s_advsound.cpp @@ -416,7 +416,7 @@ static int S_AddSound (const char *logicalname, int lumpnum, FScanner *sc) sfxid = soundEngine->FindSoundNoHash (logicalname); - if (sfxid > 0) + if ((unsigned int)sfxid < S_sfx.Size()) { // If the sound has already been defined, change the old definition sfxinfo_t *sfx = &S_sfx[sfxid];