Actually no, the idea is slightly different...
Posted Jul 18, 2009 0:57 UTC (Sat) by
khim (subscriber, #9252)
In reply to:
undefined behaviour by foom
Parent article:
Linux 2.6.30 exploit posted
GCC would be within its rights to automatically exec NetHack
whenever you dereference a null pointer. :) But instead it chooses to
assume that the program will crash, and optimizes the rest of the program
accordingly.
No, no, no. Nothing of the sort. Idea is different and it's somewhat
simpler:
1. Behavior is undefined so program can do anything it wants. It can
destroy the world for god's sake!
2. Program which can destroy the world is pretty useless so obviously
people will not write such program.
3. Ergo program is withing defined behavior. Somehow. Compiler does not
need to guarantee that - it's programmer's responsibility.
4. This means some other part of program checks the pointer for NULL (even
if compiler has no idea which one).
5. And that means the next check is redundant and can be removed.
That's why it's so hard to undertand for the outsider the discussion
which goes in cyrcles when GCC developers talk with normal users:
A. This result is totally ridiculous - fix it!
B. This is undefined behavior - fix your program. WONTFIX.
A. What do you mean "undefined behavior"? It introduces security bugs.
B. This is undefined behavior - fix your program. WONTFIX.
A. Argh. This is all just stupid: how can you even imagine such behavior?
.
B. This is UNDEFINED behavior - fix your program. WONTFIX.
Ad infinitum...
GCC developer really don't care what happens to the program with
undefined behavior. Not one jot. What happens - will happens. ICE, crash,
whatever. The programmer must ensue his (or her) program does not contain
undefined constructs - then and only then it's time to complain.
Note: not all behaviors come from C standard. Some come from other
standards, some come from descussions from in mailing lists (for example if
you go with C standard it becomes impossible to write multithreaded
programs so there are some additiona guarantees invented by GCC
developers). But if you agree that something is "undefined behavior" then
the resolution WONTFIX comes automatically.
(
Log in to post comments)