From 380e92ce7e5befac890b63be28e534e4c8b545be Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 3 Feb 2018 00:51:48 +0100 Subject: [PATCH] added boundary checks for sound/music ID for some sound and music functions - this causes game music with negative music ID not being played anymore - negative music IDs are used for (game) music files not specified in a GIC - playing game music with negative ID will be fixed in the next commit --- src/libgame/sound.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index ea055503..8a5ab84e 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -687,41 +687,57 @@ int getMusicListSize() struct FileInfo *getSoundListEntry(int pos) { + int num_sounds = getSoundListSize(); int num_list_entries = sound_info->num_file_list_entries; int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries); + if (pos < 0 || pos >= num_sounds) /* invalid sound */ + return NULL; + return (pos < num_list_entries ? &sound_info->file_list[list_pos] : &sound_info->dynamic_file_list[list_pos]); } struct FileInfo *getMusicListEntry(int pos) { + int num_music = getMusicListSize(); int num_list_entries = music_info->num_file_list_entries; int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries); + if (pos < 0 || pos >= num_music) /* invalid music */ + return NULL; + return (pos < num_list_entries ? &music_info->file_list[list_pos] : &music_info->dynamic_file_list[list_pos]); } static SoundInfo *getSoundInfoEntryFromSoundID(int pos) { + int num_sounds = getSoundListSize(); int num_list_entries = sound_info->num_file_list_entries; int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries); SoundInfo **snd_info = (SoundInfo **)(pos < num_list_entries ? sound_info->artwork_list : sound_info->dynamic_artwork_list); + if (pos < 0 || pos >= num_sounds) /* invalid sound */ + return NULL; + return snd_info[list_pos]; } static MusicInfo *getMusicInfoEntryFromMusicID(int pos) { + int num_music = getMusicListSize(); int num_list_entries = music_info->num_file_list_entries; int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries); MusicInfo **mus_info = (MusicInfo **)(pos < num_list_entries ? music_info->artwork_list : music_info->dynamic_artwork_list); + if (pos < 0 || pos >= num_music) /* invalid music */ + return NULL; + return mus_info[list_pos]; } -- 2.34.1