mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: "Gary E. Miller" <gem@rellim.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] ✘strerror_r() bug in musl
Date: Tue, 12 Apr 2022 23:44:11 -0400	[thread overview]
Message-ID: <20220413034411.GS7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <20220412134355.59bd920e@spidey.rellim.com>

On Tue, Apr 12, 2022 at 01:43:55PM -0700, Gary E. Miller wrote:
> 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).

This is really a deficiency of the documentation. The text that's
there isn't factually wrong but it's in some sense wrong by omission
-- it omits clearly stating that _GNU_SOURCE does not change anything
to behave in ways that conflict with the standards-specified behaviors
(or change the behavior of standards-specified interfaces whatsoever).
It *only* exposes extension interfaces.

In addition to correcting this, the "criteria for exclusion/inclusion"
of extension functionality should really be written up well and placed
in a conspicuous place. At present it's just scattered across mailing
list discussions of various proposed extensions.

And likewise, the specific example of `strerror_r` (note: `basename`
is like this and is already covered) should be mentioned on the wiki
"differences from glibc" page.

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

The code should not even compile if it's using the wrong signature.
The GNU version of the function does not guarantee that the string is
stored in the provided buf, so you have to examine the return value,
and assignment/passing of an int where a pointer type is expected is a
constraint violation. By default gcc only treats this as a warning
(-Wint-conversion) but you can and should make it an error via
-Werror=int-conversion since code doing this is unconditionally wrong.

Rich

  parent reply	other threads:[~2022-04-13  3:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 20:43 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 [this message]
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=20220413034411.GS7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=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).