tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: NULL pointer arithmetic issues



On Sun, Mar 08, 2020 at 03:33:57PM +0100, Kamil Rytarowski wrote:
> There was also a request to make a proof that memcpy(NULL,NULL,0) is UB
> and can be miscompiled.
> 
> Here is a reproducer:
> 
> http://netbsd.org/~kamil/memcpy-ub.c
> 
> 131 kamil@rugged /tmp $ gcc -O0 memcpy.c
> 
> 132 kamil@rugged /tmp $ ./a.out
> 
> 1
> 
> 133 kamil@rugged /tmp $ gcc -O2 memcpy.c
> 134 kamil@rugged /tmp $ ./a.out
> 0
> 
> A fallback for freestanding environment is to use
> -fno-delete-null-pointer-check.

The correct fix is not to disable the null-pointer-check option but to
remove the broken automatic non-null arguments in GCC.

Joerg


Home | Main Index | Thread Index | Old Index