diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4e0c03d11..85b169818 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20101113 -------- main/playsave.c: In plyr_save_stats setting filename to size of PATH_MAX to have enough space to also hold the player directory prefix which would otherwise create a memory corruption and crash the game +arch/sdl/jukebox.c: Make sure read_m3u won't read past the end of the buffer, causing a crash 20101109 -------- diff --git a/arch/sdl/digi_mixer_music.c b/arch/sdl/digi_mixer_music.c index 2c3b08d2f..9a2692a95 100644 --- a/arch/sdl/digi_mixer_music.c +++ b/arch/sdl/digi_mixer_music.c @@ -59,7 +59,7 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)()) if (!current_music) current_music = Mix_LoadMUS(filename); - // no luck. so it might be in Searchpath. So try to build absolute path + // no luck. so either it's in an archive or Searchpath if (!current_music) { PHYSFSX_getRealPath(filename, full_path); @@ -68,18 +68,15 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)()) filename = full_path; // used later for possible error reporting } - // still nothin'? Let's open via PhysFS in case it's located inside an archive if (!current_music) - { filehandle = PHYSFS_openRead(filename); - if (filehandle != NULL) - { - current_music_hndlbuf = d_realloc(current_music_hndlbuf, sizeof(char *)*PHYSFS_fileLength(filehandle)); - bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), PHYSFS_fileLength(filehandle)); - rw = SDL_RWFromConstMem(current_music_hndlbuf,bufsize*sizeof(char)); - PHYSFS_close(filehandle); - current_music = Mix_LoadMUS_RW(rw); - } + if (filehandle != NULL) + { + current_music_hndlbuf = d_realloc(current_music_hndlbuf, sizeof(char *)*PHYSFS_fileLength(filehandle)); + bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), PHYSFS_fileLength(filehandle)); + rw = SDL_RWFromConstMem(current_music_hndlbuf,bufsize*sizeof(char)); + PHYSFS_close(filehandle); + current_music = Mix_LoadMUS_RW(rw); } if (current_music) diff --git a/arch/sdl/jukebox.c b/arch/sdl/jukebox.c index a3b75c546..cf39b4348 100644 --- a/arch/sdl/jukebox.c +++ b/arch/sdl/jukebox.c @@ -101,7 +101,7 @@ void read_m3u(void) JukeboxSongs.max_buf = length + 1; buf = JukeboxSongs.list_buf; - while (buf < JukeboxSongs.list_buf + length) + while (buf < JukeboxSongs.list_buf + length - 1) { while (*buf == 0 || *buf == 10 || *buf == 13) // find new line - support DOS, Unix and Mac line endings buf++;