Skip to contentSkip to conversation

C undefined behavior fix

PATCH [email protected] 3 participants 3 messages Jan 3, 2002 – Jan 6, 2002

lore
Share & tools
lore
#0 lore raw

<<This is a modification to gcc that implements pointers as triples. While there is a performance penalty for doing this, it can completely eliminate the problem of exploitable buffer overflows. However, programs that violate the rules of ISO C by generating out-of-range pointers will fail.

Quoted 1 line
Quoted 1 line

Note incidentally that the C rules that allow referencing the address just past the end of an array (an irregularity that recognizes the infeasibility of declaring the common idiom for (a=b;a<&b[10];a++)) has an interesting consequence on a segmented machine, namely that you cannot allocate an array too near the end of the segment.

#1 lore raw
Quoted 6 lines · On Wed, Jan 02, 2002 at 07:12:41PM -0500, [email protected] wrote:

Note incidentally that the C rules that allow referencing the address just past the end of an array (an irregularity that recognizes the infeasibility of declaring the common idiom for (a=b;a<&b[10];a++)) has an interesting consequence on a segmented machine, namely that you cannot allocate an array too near the end of the segment.

At the risk of going off topic, you can take the non-element's address but you can't actually touch it. So provided your architecture supports pointer arithmetic beyond the end of the segment, your only remaining worries are (1) that you don't stumble into the NULL address (which need not be zero), and (2) that the address isn't reused as a valid element of something else. I'm not so sure the latter is even a requirement.

Which does tie in to what we were discussing: in "foo"+LARGE_CONSTANT, the problem is that C makes no promises on where "foo" ends up in memory, or if it's even a single place, or what is located at any given offset from it, or that the sum is even something that can be considered an address in any way. Nor does the compiler need to assume that the programmer knows better--bar some compiler-specific support for this trick.

Jeroen

(Yes, I'm a pedant. I'm pining for the day when gcc will support the options "-ffascist -Wanal")

#2 lore raw
In reply to [email protected]
Quoted 2 lines · jtv

(Yes, I'm a pedant. I'm pining for the day when gcc will support the options "-ffascist -Wanal")

How about introducing the options `-flame -War' :-)

Signature · 4 lines
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me