alsa-project / alsa-lib

The Advanced Linux Sound Architecture (ALSA) - library
GNU Lesser General Public License v2.1
366 stars 177 forks source link

alsatplg broken with musl-libc #187

Closed Johnnynator closed 2 years ago

Johnnynator commented 2 years ago

alsatplg feeds empty and non Integer strings to strtol(3) and friends. Glibc just silently accepts such inputs and does not set errno and returns 0. Musl sets errno to EINVAL with such inputs. This can easily be seen by most of the alsatplg invocation when compiling https://github.com/thesofproject/sof/

STRTOL(3) manpage explains that this behavior is allowed.

The implementation may also set errno to EINVAL in case no conversion was performed (no digits seen, and 0 returned).

There are like two ways I see this can be fixed

a) ignore EINVAL (and check if base is correct ourself) b) make sure that strtol is only getting called with a valid input (I'm not sure if the current behavior is intended to just return 0 if e,g, tplg_get_unsigned did not even parse anything valid

perexg commented 2 years ago

I would use safe_strtol() function and check for the valid input - commit 5fab157a593180525607b7d26263bee127f6be36 . I think that NULL pointer is not passed to strtol.

@plbossart , @ranj063 : FYI. It seems that the buggy input is parsed.

perexg commented 2 years ago

Fix is available, reopen in case of other issues.