Date: Tue, 12 Apr 2022 13:43:55 -0700 From: "Gary E. Miller" <gem@...lim.com> To: musl@...ts.openwall.com Subject: ✘strerror_r() bug in musl Yo All! I'm new to the list. I;ve been trying to report a musl bug on #musl since last Friday, but no one seems to live there. musl (all versions) has a bug in strerror_r(). The musl reference manual says of _GNUSOURCE: _GNU_SOURCE (or _ALL_SOURCE) Adds everything above, plus interfaces modeled after GNU libc extensions and interfaces for making use of Linux-specific features. I take that to mean that when _GNU_SOURCE is used to compile code with musl that the results will behave as GNU libc (glinc). The muls code in include/string.h, line 68 says: #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); int strerror_r (int, char *, size_t); [...] So strerro_r() always returns an int if _GNU_SOURCE, POSIX_SOURCE, etc. is defined. But the glibc man page for strerror_r() ssys: int strerror_r(int errnum, char *buf, size_t buflen); /* XSI-compliant */ char *strerror_r(int errnum, char *buf, size_t buflen); /* GNU-specific */ When _GNU_SOURCE is defined with glibc, then strerror_r() returns a char *. The man page continues: strerror_r(): The XSI-compliant version is provided if: (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE Otherwise, the GNU-specific version is provided. The glibc include/string.h, line 420, clarifies things a bit: #ifdef __USE_XOPEN2K /* Reentrant version of `strerror'. There are 2 flavors of `strerror_r', GNU which returns the string and may or may not use the supplied temporary buffer and POSIX one which fills the string into the buffer. To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L without -D_GNU_SOURCE is needed, otherwise the GNU version is preferred. */ # if defined __USE_XOPEN2K && !defined __USE_GNU /* Fill BUF with a string describing the meaning of the `errno' code in ERRNUM. */ # ifdef __REDIRECT_NTH extern int __REDIRECT_NTH (strerror_r, (int __errnum, char *__buf, size_t __buflen), __xpg_strerror_r) __nonnull ((2)) __attr_access ((__write_only__, 2, 3)); # else extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen) __THROW __nonnull ((2)) __attr_access ((__write_only__, 2, 3)); # define strerror_r __xpg_strerror_r # endif Is if musl intends its strerror_r() to work like glibc's strerror_r() then there is a bug. Particularly nasty to have functions that only run when an error condition occurs, to themselves cause crashes. RGDS GARY --------------------------------------------------------------------------- Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703 gem@...lim.com Tel:+1 541 382 8588 Veritas liberabit vos. -- Quid est veritas? "If you can't measure it, you can't improve it." - Lord Kelvin Content of type "application/pgp-signature" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.