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