Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 24 Feb 2023 11:12:11 -0500
From: Tamir Duberstein <>
To: NRK <>
Cc: Rich Felker <>,
Subject: Re: undefined behavior in fread.c

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:;l=1099;drc=4aa8f499f21ebf84101de34d68682d5388667001

Does this persuade?

On Fri, Feb 24, 2023 at 10:13 AM NRK <> 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
> 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

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.