From: Holger Schemel Date: Fri, 2 Feb 2018 23:51:48 +0000 (+0100) Subject: added boundary checks for sound/music ID for some sound and music functions X-Git-Tag: 4.0.1.1~2 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=380e92ce7e5befac890b63be28e534e4c8b545be;p=rocksndiamonds.git 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 --- 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]; }