mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] ✘strerror_r() bug in musl
@ 2022-04-12 20:43 Gary E. Miller
  2022-04-12 20:48 ` alice
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Gary E. Miller @ 2022-04-12 20:43 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 3113 bytes --]

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@rellim.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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 851 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-04-13 23:07 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 20:43 [musl] ✘strerror_r() bug in musl Gary E. Miller
2022-04-12 20:48 ` alice
2022-04-12 21:04   ` Gary E. Miller
2022-04-12 20:56 ` Alex Xu (Hello71)
2022-04-12 21:07   ` Gary E. Miller
2022-04-12 23:16     ` Wolf
2022-04-13  0:15       ` Gary E. Miller
2022-04-12 21:13   ` Gary E. Miller
2022-04-13  3:44 ` Rich Felker
2022-04-13 12:24 ` [musl] *strerror_r() " Natanael Copa
2022-04-13 14:05   ` Rich Felker
2022-04-13 17:36     ` Gary E. Miller
2022-04-13 20:38       ` Rich Felker
2022-04-13 21:16         ` Gary E. Miller
2022-04-13 22:27           ` Rich Felker
2022-04-13 22:43             ` Gary E. Miller
2022-04-13 22:58               ` Rich Felker
2022-04-13 23:07                 ` Gary E. Miller

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).