Skip to content

Commit

Permalink
if the backend sets a different sample rate, check if it is supported:
Browse files Browse the repository at this point in the history
WildMidi_Init() accepts uint16_t as rate, therefore, reject any values
greater than 65535.
  • Loading branch information
sezero committed Apr 4, 2024
1 parent cc87a74 commit 71e99e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/player/out_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ static int open_alsa_output(const char *pcmname, unsigned int *rate) {
goto fail;
}
if (r != *rate) {
if (*rate > 65535) { /* WildMidi_Init() accepts uint16_t as rate */
fprintf(stderr, "ALSA: an unsupported sample rate (%uHz) was set\r\n", *rate);
goto fail;
}
fprintf(stderr, "ALSA: sample rate set to %uHz instead of %u\r\n", *rate, r);
}

Expand Down
11 changes: 9 additions & 2 deletions src/player/out_netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,21 @@ static int open_netbsd_output(const char *pcmname, unsigned int *rate)
ainfo.blocksize = 0;

if (ioctl(audio_fd, AUDIO_SETINFO, &ainfo) < 0) {
fprintf(stderr, "netbsdaudio: AUDIO_SETINFO failed!\n");
fprintf(stderr, "netbsdaudio: AUDIO_SETINFO failed!\r\n");
goto err1;
}
if (ioctl(audio_fd, AUDIO_GETINFO, &ainfo) < 0) {
err0:
fprintf(stderr, "netbsdaudio: AUDIO_GETINFO failed!\n");
fprintf(stderr, "netbsdaudio: AUDIO_GETINFO failed!\r\n");
goto err1;
}
if (ainfo.play.sample_rate != *rate) {
if (ainfo.play.sample_rate > 65535) { /* WildMidi_Init() accepts uint16_t as rate */
fprintf(stderr, "netbsdaudio: an unsupported sample rate (%uHz) was set\r\n", ainfo.play.sample_rate);
goto fail;
}
fprintf(stderr, "netbsdaudio: sample rate set to %uHz instead of %u\r\n", ainfo.play.sample_rate, *rate);
}
*rate = ainfo.play.sample_rate;

return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/player/out_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ static int open_oss_output(const char *pcmname, unsigned int *rate) {
goto fail;
}
if (r != *rate) {
if (*rate > 65535) { /* WildMidi_Init() accepts uint16_t as rate */
fprintf(stderr, "OSS: set an unsupported sample rate (%uHz) was set\r\n", *rate);
goto fail;
}
fprintf(stderr, "OSS: sample rate set to %uHz instead of %u\r\n", *rate, r);
}

Expand Down
7 changes: 7 additions & 0 deletions src/player/out_sndio.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ static int open_sndio_output(const char *output, unsigned int *rate)
goto error;
}

if (par.rate != *rate) {
if (par.rate > 65535) { /* WildMidi_Init() accepts uint16_t as rate */
fprintf(stderr, "sndio: an unsupported sample rate (%uHz) was set\r\n", par.rate);
goto fail;
}
fprintf(stderr, "sndio: sample rate set to %uHz instead of %u\r\n", par.rate, *rate);
}
*rate = par.rate; /* update rate with the received value */
return 0;

Expand Down

0 comments on commit 71e99e8

Please sign in to comment.