bind(2): Missing [[gnu::nonnull]]
Florian Weimer
fweimer@redhat.com
Sun Dec 4 18:46:15 GMT 2022
* Alejandro Colomar via Libc-alpha:
> Hi Xi,
>
> On 12/4/22 06:59, Xi Ruoyao wrote:
>> On Sat, 2022-12-03 at 20:05 +0100, Andreas Schwab wrote:
>>>> Currently the man page says:
>>>>
>>>> EFAULT: addr points outside the user's accessible address space.
>>>>
>>>> And bind(2) indeed sets errno to EFAULT and return -1 when NULL is
>>>> passed as addr.
>>>
>>> You can never depend on EFAULT for invalid addresses.
>> Hmm, is this documented somewhere?
>
> I don't know, but let me have an educated guess:
>
> Holding a pointer to invalid memory is Undefined Behavior by the
> standard, except if that pointer is NULL, or is still indeterminate
> because the pointer has not yet been initialized with a valid address.
> Using an uninitialized pointer is UB as using any uninitialized
> variable. Using a NULL pointer is only okay for comparisons, or as a
> sentinel value, but never for accessing memory. So chances are high
> that the program will already have invoked UB at the time bind(2) is
> called with an invalid address.
Currently, Linux does not report for vDSO-accelerated system calls, but
generates SIGSEGV. We received bug reports when we added vDSO support
for time/gettimeofday/clock_gettime because some tests were relying on
the EFAULT behavior.
Thanks,
Florian
More information about the Libc-alpha
mailing list