Skip to content

Commit

Permalink
sndio: use sio_nfds
Browse files Browse the repository at this point in the history
Instead of guessing the number of needed pollfd structures, use sio_nfds
and allocate the number of required structures.
If libsndio uses its alsa backend then in my tests the number of
required pollfds is 16, larger than the previously defined MAXFDs.
This resulted in sio_pollfd overwriting stack memory.
  • Loading branch information
Duncaen authored and kinetiknz committed Dec 10, 2019
1 parent a71f116 commit 3025cbe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cubeb_sndio.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
X(sio_eof) \
X(sio_getpar) \
X(sio_initpar) \
X(sio_nfds) \
X(sio_onmove) \
X(sio_open) \
X(sio_pollfd) \
Expand Down Expand Up @@ -135,18 +136,23 @@ sndio_onmove(void *arg, int delta)
static void *
sndio_mainloop(void *arg)
{
#define MAXFDS 8
struct pollfd pfds[MAXFDS];
struct pollfd *pfds;
cubeb_stream *s = arg;
int n, eof = 0, prime, nfds, events, revents, state = CUBEB_STATE_STARTED;
size_t pstart = 0, pend = 0, rstart = 0, rend = 0;
long nfr;

nfds = WRAP(sio_nfds)(s->hdl);
pfds = calloc(nfds, sizeof (struct pollfd));
if (pfds == NULL)
return NULL;

DPR("sndio_mainloop()\n");
s->state_cb(s, s->arg, CUBEB_STATE_STARTED);
pthread_mutex_lock(&s->mtx);
if (!WRAP(sio_start)(s->hdl)) {
pthread_mutex_unlock(&s->mtx);
free(pfds);
return NULL;
}
DPR("sndio_mainloop(), started\n");
Expand Down Expand Up @@ -274,6 +280,7 @@ sndio_mainloop(void *arg)
s->hwpos = s->swpos;
pthread_mutex_unlock(&s->mtx);
s->state_cb(s, s->arg, state);
free(pfds);
return NULL;
}

Expand Down

0 comments on commit 3025cbe

Please sign in to comment.