That sounds like a pretty broken compiler, do you have a minimal example?
That sounds like a pretty broken compiler, do you have a minimal example?
void
encrypt(void *data, size_t len, char *password)
{
char key[32];
turn_password_into_key(password, key, sizeof key);
aes_make_encrypted(data, len, key);
memset(key, 0, sizeof key); /* optimized away */
}
The compiler knows what memset does. It also knows that stack variables have no use after the function returns. Therefore, the compiler knows there is no reason to write zeroes to this memory, because the program will never read those zeroes. Hence, the compiler will delete the call to memset.Backdoors in source can be as simple as changing a single == to = or removing a minus sign in some seemingly innocuous place.
However there are plenty of examples of compilers aggressively removing code that causes undefined behaviour. Basically, when the compiler encounters UB, it can do whatever it wants to code that triggers the UB, which means possibly removing it. Compilers exploit this fact a lot because UBs happen a lot in "normal code". See here [2] for examples and explanations; I also can't help but mention John Regehr's blog [3] if you're interested in compilers, security, testing, safety.
[1] http://research.swtch.com/openssl
[2] http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
[3] http://blog.regehr.org/archives/213 is a great article for example.