News for hackers. Stuff that matters.
Re:Chromium project finds that 70% of security defects are m... by kelnos on Sunday May 24, 2020 @04:15AM (#23290039)
> So-called "modern C++", using std::string, RAII, unique_ptr (and shared_ptr).

And yet we see the same memory-safety bugs come up time and time again in supposedly-modern C++ programs. So either this modern way is not enough to avoid these classes of bugs, or people very quickly fall to the temptation to use unsafe constructs due to performance or just because it's easier to write.

We're humans. If there's an easier way to do something, even if it's less safe, we'll invariably do it sometimes. I like that Rust makes it harder to do so, and makes you explicitly say that you want to do something unsafe, which I imagine deters a lot of people from going down those paths. And when someone writes a memory-safety bug in unsafe Rust, they get much more egg on their face than if they were to write the same bug in C++.

Re:Chromium project finds that 70% of security defects are m... by pnako on Sunday May 24, 2020 @07:23AM (#23290786)
How does that help though?

The memory management issues in my C++ programs (recently, real-time audio stuff) are where I explicitly decide not to use modern C++ / automated memory management, and write my own allocators that rely on malloc/free or some variant (aligned_alloc, etc.)

In Rust I suppose I would just use an unsafe block and have the exact same issues.

Note that good unit testing, assertions and sanitizers generally take care of the issue.

Re:Chromium project finds that 70% of security defects are m... by db48x on Sunday May 24, 2020 @10:35AM (#23291796)
Allocators are not the only source of memory-safety bugs, and RAII can't fix all problems. In particular, aliasing probably caused most of the safety problems Chrome has had to deal with (I admit that I haven't gone and counted them). This is especially true for use-after-free bugs, where some part of the code has a pointer to some memory that has been deallocated; there's not much way for that to happen without aliasing. In Rust, memory can only be deallocated if there are no outstanding references to it. That can be determined at compile time (specifically by the borrow checker), or at run time using reference counter.

Unit tests, assertions, and sanitizers are nice, but they demonstrably don't work; Chrome and Firefox use all three. They have hundreds of thousands or millions of tests, assertions on every other line, and all kinds of compile-time sanitizers but they still have hundreds of memory safety problems a year.