3 ms·
Pointers to stack objects escaping the function (not necessarily returning) is actually surprisingly easy to do. Sure, the example "Foo f; return &f;" is the so
by jcranmer 9y ago
Pointers to stack objects escaping the function (not necessarily returning) is actually surprisingly easy to do. Sure, the example "Foo f; return &f;" is the sort of situation that isn't going to happen if you're at all experienced, but it's not hard to build cases. I recently had to debug a crash which turned out to be a stack object unexpectedly escaping. Effectively, the flow is this:
void foo(Foo *v) {
Operand blah;
/* Turns out that there's a use-list on some operands, and this adds &blah to that list in that case. */
copy_operand(&blah, &v->operands[1]);
free_foo(v);
}
> A combination of valgrind/sanitizers will catch all of these mistakes.
They will catch only those mistakes that occur when you run them in tests. Plenty of memory safety CVEs still show up in programs that do aggressive fuzzing under valgrind/sanitizer testing. Or, as one aphorism has it, "testing cannot prove the absence of bugs, only their presence."