From: "Gary E. Miller" <gem@rellim.com>
To: musl@lists.openwall.com
Subject: [musl] ✘strerror_r() bug in musl
Date: Tue, 12 Apr 2022 13:43:55 -0700 [thread overview]
Message-ID: <20220412134355.59bd920e@spidey.rellim.com> (raw)
[-- 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 --]
next reply other threads:[~2022-04-12 20:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-12 20:43 Gary E. Miller [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220412134355.59bd920e@spidey.rellim.com \
--to=gem@rellim.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).