A zero pointer is not a null pointer
Posted Jul 25, 2009 2:51 UTC (Sat) by giraffedata
In reply to: A zero pointer is not a null pointer
Parent article: Fun with NULL pointers, part 1
GCC certainly doesn't insert code checking if a pointer is NULL before
every pointer dereference.
Sure, but that wouldn't improve standards compliance anyway. I asked if GCC generates extra code to comply with the C99 requirement that a null pointer not be equal to any non-null one (while still allowing the existence of pointers to a data structure that resides at address 0). Thinking about it now, though, I don't see how any such code is possible since a null pointer still has to compare equal to another null pointer.
That kernel space has to work when the lower part of its address space is
effectively under the control of a hostile attacker is a unique problem
which it is really not worth changing the C standard for,
There has been no proposal to deal with this by changing the standard,
which GCC apparently ignores anyhow. And objection to GCC's conflation of null pointers and zero-address pointers wasn't that it's a security problem but that it's a basic correctness problem. Even without a hostile page 0, unless you proclaim data structures at address 0 don't exist, this optimization breaks code.
to post comments)