3 ms·
1) malloc absolutely returns NULL on Linux, even with overcommit. Using setrlimit (which properly sandboxed daemons should be doing), it's trivial to get malloc
by wahern 12y ago
1) malloc absolutely returns NULL on Linux, even with overcommit. Using setrlimit (which properly sandboxed daemons should be doing), it's trivial to get malloc to return NULL.
2) The issue isn't whether malloc returns NULL. Technically speaking, unsigned arithmetic doesn't even "overflow", which in C is a term meaning the result is undefined. It returns the value modulo 2^N. In other words, in the vast majority of situations malloc will succeed, but return a buffer smaller than you requested.
3) According to your logic, people shouldn't check object boundaries, either. Many buffer overflow exploits utilize arithmetic overflow, because usually the memory you're interested is nowhere near the object you're overflowing. And we know these overflows happen and can be triggered even when the application isn't using very much memory.
People with your opinions shouldn't be allowed anywhere near C code.