map

minimalistic audio player
git clone https://porkepik.fr/map
Log | Files | Refs | README | LICENSE

commit 3c173429db347f68f5a83aaf9c8ccd33dd096fd5
parent e6731d5a9beda128fddf9a281b5206b3bdd7f582
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Tue, 20 Aug 2019 14:16:34 +0200

fix stack buffer overflow

Diffstat:
Mmap.c | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/map.c b/map.c @@ -206,8 +206,6 @@ init_track(const char *curdir, const char *d_name) temp->close = vorbis_close; temp->length = vorbis_length(temp->filename); temp->format = "Vorbis"; - } else { - return NULL; } temp_len = strlen(strrchr(temp->filename, '/') + 1); @@ -225,20 +223,21 @@ static struct track ** get_tracks(const char *curdir) { struct track **tracks = NULL; - struct track *temp; - DIR *d; struct dirent *dir; + DIR *d; if (!(d = opendir(curdir))) return NULL; while ((dir = readdir(d))) { if (dir->d_type != DT_REG) continue; - temp = init_track(curdir, dir->d_name); - if (temp == NULL) + if (!strend(dir->d_name, ".flac") && + !strend(dir->d_name, ".mp3") && + !strend(dir->d_name, ".vorbis") && + !strend(dir->d_name, ".wav")) continue; - tracks = realloc(tracks, sizeof(temp) * (ntracks+1)); - tracks[ntracks++] = temp; + tracks = realloc(tracks, sizeof(struct track *) * (ntracks+1)); + tracks[ntracks++] = init_track(curdir, dir->d_name); } closedir(d); return tracks; @@ -317,7 +316,7 @@ playtrack(struct track curtrack, struct player player, int trackid) int timer_sec = 0, toptrack = 0; long done; time_t start, pause_time = 0; - short buffer[BUFF_SIZE]; + int buffer[BUFF_SIZE]; start = time(NULL); open_track(curtrack); @@ -439,11 +438,11 @@ main(int argc, char **argv) if (ntracks == 0) errx(1, "No audio files found in %s", player.curdir); - init_term(); qsort(tracks, ntracks, sizeof(*tracks), trackcmp); player.tracklist = malloc(ntracks * sizeof(char *)); build_track_list(tracks, player.tracklist); player.volume = alsa_vol(player.volume, 0); + init_term(); while (trackid < ntracks) trackid = playtrack(*tracks[trackid], player, trackid);