From: Tamir Duberstein <email@example.com>
To: NRK <firstname.lastname@example.org>
Cc: Rich Felker <email@example.com>, firstname.lastname@example.org
Subject: Re: [musl] undefined behavior in fread.c
Date: Fri, 24 Feb 2023 11:12:11 -0500 [thread overview]
Message-ID: <CAK-_uh5faEm+biUshK_R9q_p7OqKv+_CsBYq-9V+1DhzE5Y97Q@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1764 bytes --]
I agree, the caller's behavior is UB. I'll send them (freetype2) a patch.
That said, do we want to avoid internal UB here anyway?
- As mentioned earlier, glibc avoids the UB (and the lock).
- llvm-libc does the same starting with
- uclibc avoids the UB but still locks:
- FreeBSD avoids the UB but still locks:
- Android (bionic) avoids the UB but still locks:
Does this persuade?
On Fri, Feb 24, 2023 at 10:13 AM NRK <email@example.com> wrote:
> On Fri, Feb 24, 2023 at 09:42:00AM -0500, Tamir Duberstein wrote:
> > We could take the lock and still avoid UB with an early return.
> As Jens has pointed out, the UB in this case is the caller calling fread
> with NULL - not in musl.
> And on a sidenote, I've always found - especially for the various mem*
> functions - accepting 0 size but not accepting NULL arg (when n is 0) to
> be a poor choice. A lot of the value that accepting 0 size provides is
> diminished by not accepting NULL.
> And this affects more than just libc, too. Compilers like gcc/clang will
> see a call like `memcmp(p, q, 0)` and will ""determine"" `p` and `q` are
> non-null (which can lead to deleting any subsequent null-checks on those
> But anyways, that was just a small rant.
> As things currently are, *even if* musl deal with the NULL pointer - any
> caller calling fread with NULL is still in danger from compilers and
> needs to fix it on their side.
> - NRK
[-- Attachment #2: Type: text/html, Size: 2658 bytes --]
next prev parent reply other threads:[~2023-02-24 16:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 12:52 Tamir Duberstein
2023-02-24 13:34 ` Rich Felker
2023-02-24 13:53 ` Jₑₙₛ Gustedt
2023-02-24 13:55 ` NRK
2023-02-24 14:07 ` Rich Felker
2023-02-24 14:17 ` NRK
2023-02-24 14:42 ` Tamir Duberstein
2023-02-24 15:13 ` NRK
2023-02-24 16:12 ` Tamir Duberstein [this message]
2023-02-24 16:40 ` Jₑₙₛ Gustedt
2023-02-24 16:42 ` Tamir Duberstein
2023-02-24 17:00 ` Jₑₙₛ Gustedt
2023-02-24 17:07 ` enh
2023-02-24 17:32 ` Tamir Duberstein
2023-02-24 16:42 ` enh
2023-02-24 20:07 ` Rich Felker
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:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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
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).