Skip to content

Commit

Permalink
audio: Fix false positives in driver name comparison
Browse files Browse the repository at this point in the history
Without this change, driver names don't get matched correctly;
for example "a" can get matched with "alsa" since it only checks
whether the string matches up to the length of the requested
driver name.
  • Loading branch information
dos1 authored and slouken committed Aug 10, 2021
1 parent b3a989d commit 25f9ed8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/audio/SDL_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,8 @@ SDL_AudioInit(const char *driver_name)
: SDL_strlen(driver_attempt);

for (i = 0; bootstrap[i]; ++i) {
if (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0) {
if ((driver_attempt_len == SDL_strlen(bootstrap[i]->name)) &&
(SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0)) {
tried_to_init = 1;
SDL_zero(current_audio);
current_audio.name = bootstrap[i]->name;
Expand Down

1 comment on commit 25f9ed8

@sulix
Copy link
Contributor

@sulix sulix commented on 25f9ed8 Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out there were a few distros inadvertantly relying on this:
https://bugzilla.opensuse.org/show_bug.cgi?id=1189778

Specifically, because SDL 1.2 used pulse as the name of the PulseAudio backend and SDL 2.0 uses pulseaudio, distros which set SDL_AUDIODRIVER=pulse somewhere used to work, but broke with SDL 2.0.16.

Do we want to:

  • Ignore it, the distros will fix whatever's setting the variable.
  • Revert this, as it broke things.
  • Special-case "pulse" and "pulseaudio", so that there is a consistant way of using PulseAudio across SDL 1.2 and SDL 2.0?

Please sign in to comment.