mailing list of musl libc
 help / color / mirror / code / Atom feed
From: NRK <nrk@disroot.org>
To: Tamir Duberstein <tamird@google.com>
Cc: Rich Felker <dalias@libc.org>, musl@lists.openwall.com
Subject: Re: [musl] undefined behavior in fread.c
Date: Fri, 24 Feb 2023 21:13:34 +0600	[thread overview]
Message-ID: <20230224151334.ycgddzdc4o5a4m5q@gen2.localdomain> (raw)
In-Reply-To: <CAK-_uh655WeD52j426MnxGG1F6N-MW3OtkHMsSzEnhf5suxSsw@mail.gmail.com>

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

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

  reply	other threads:[~2023-02-24 15:13 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 [this message]
2023-02-24 16:12             ` Tamir Duberstein
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

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=20230224151334.ycgddzdc4o5a4m5q@gen2.localdomain \
    --to=nrk@disroot.org \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=tamird@google.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).