153 points · by todsacerdoti · 2y ago · 29 comments
https://news.ycombinator.com/item?id=37479651
“All decent C compilers have compilation options so that at run-time any undefined actions, including integer overflow and out-of-bounds accesses, will be trapped.”
“Despite the hype, by default Rust is not safer than C compiled with the right options, because the default for Rust releases is also to omit many run-time checks.”
https://news.ycombinator.com/item?id=25922430
Upthread someone asks for a “-safe” flag which makes C a safe language. The reply is “It's called AddressSanitizer. You enable it with the compiler flag -fsanitize=address.” Several replies ensue pointing out how wrong this is.
C or C++ w/o ASan and UBSan is like skydiving w/o a parachute.
Unfortunately the documentation for the great number of sanitizers available in gcc and clang is both voluminous and incomplete.
For all of them their internals should have been very clearly documented, like in this article about ASAN.
Does anyone know of a good explanation of HWAddress Sanitizer internals?
One for ARMv8 with Top-Byte-Ignore: you can use the top byte of memory addresses to store a tag.
When you allocate memory you return the "tagged" pointer and internally store "this region has this tag".
When you dereference a pointer, you check that the tag matches what you expect in your internal data structure.
With memory tagging extensions you can do something similar but the checks are performed by the processor.
Basic C understanding (Memory, Stack, Heap, Syscall)."
Obviously, since C doesn't prescribe any kind of heap, stack or syscall behavior (or if they even exist), I assume the author meant something like "Basic understanding of how C is often implemented on certain operating systems and hardware".