3 ms·
> Replacing [] with at, eliminates the vulnerability. And for decades of C and C++ programmers, [] is still the most obvious way to index an array. And the mos
by JoshTriplett 7y ago
> Replacing [] with at, eliminates the vulnerability.
And for decades of C and C++ programmers, [] is still the most obvious way to index an array. And the most obvious way creates potential security vulnerabilities.
See Rusty Russell's classic "easy to use versus hard to misuse" posts: http://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html http://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html and https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html .
- blub 7y agoHistorically, C and C++ programmers didn't care much about safety, especially if they had to give up performance to reach it. This is changing in the newest C++ standards and tooling (e.g. clang's -Wlifetimes). Bounds checking is slower, so that's the main reason why it's shunned. Rust made it mandatory, but from what I've seen there are people disabling that to squeeze some drops of performance nevertheless. Luckily, I think Rust also has an option of replacing indexing with iteration, thereby avoiding the performance hit. I think it currently does this a bit better than C++, but I might be wrong. Anyway, my critique still stands, that blog post is really low effort and doesn't prove much. I've looked at some of the fixes for Firefox security bugs and the code reminds one of the typical older C++ projects with raw pointers everywhere. Perhaps implementing a browser requires all sorts of unsafe access patterns.
- JoshTriplett 7y agoThe Rust compiler can eliminate bounds checking anywhere it can prove that it doesn't need it. And beyond that, you always have the option of writing an unsafe block, and people sometimes do in carefully selected cases driven by profiling. (That also encourages keeping such code carefully contained and well-scrutinized.) I'm not arguing that bounds-checking should be mandatory. I'm arguing that bounds-checking should be the default, and you should have to knowingly bypass it, rather than the other way around.