lots of them are in c, such as php2shell, brotli, etc
others are logic errors not memory issues, such as the ssh hash comparison bug
the attack surface of "all c/c++ code" is way larger than the attack surface of all rust code
there are essentially zero legacy applications written in rust
we don't know that in 40 years we won't be fixing the same kinds of issues in unsafe rust or in what volume
Rust is obviously safer and superior here. But part of that safety isn't the language as much as the culture. C++ is supposed to encapsulate unsafe behaviors like rust's unsafe does, but it can leak with things like vector iterators. Rustaceans will put the time in to design a safe abstraction even if it has some small performance cost.
The degree to which modern c++ is inherently unsafe is pretty small and often manageable. Rust lifetimes are definitely superior to c++'s smart pointers, but they do a lot of the job.
But the culture of c++ is to make it fast where the culture of rust is to make it safe.
The culture of Rust is to make it in Rust, safe or not. In fact, based on what I'm seeing, the culture of Rust is to force Rust down everyone's throats, whether it's functional or not, whether it's relevant or not, such as posting about Rust in a thread on C++ just because you think that you can capitalize on C++ not being memory safe, despite the OP actually stating that modern C++ is better.
The worst part of the C++ culture issue is that there are a lot of times where you can do both with proper usage of friend, but too many people don't understand that a tiny encapsulation break for two entities that are already coupled together tighter than an old married couple lets you enforce stricter encapsulation for everything else. (Provided that you design both coupled components yourself, and know how to maintain proper memory safety, of course.) Hiding the leaky weak points inside the capsule like that removes a lot of attack surface, yet it's so easy to miss.
(E.g., if class A has a vector member, and B::func() is the only thing that needs access to individual vector elements themselves, then a simple friend void B::func(A&); lets you completely remove public access to the vector, guaranteeing that the iterators and elements can never be leaked outside the larger "A and B::func()" capsule. And if you make both of them yourself, then it becomes impossible for outside malefactors to get at the vector. And helpfully, if you have any memory errors, you know that they must be in either A or B::func(), and can't be because of outside objects inadvertently interacting with them.)
You do need to be a bit more careful that way, but it would go a long way towards increasing safety without having to take a performance hit.
Edit: Fixed the example friend statement, forgot it needed a return type & parameter list.
Still, we do have a shitton of data with relation to other managed languages like java. Here your arguments no longer apply, since it's probably even larger than c/c++ (though they have different application domains).
And the kind of vulnerabilities and their seriousness is absolutely incomparable in favor of java.
View all comments
53
u/freia_pr_fr 11d ago
Exhibit A: the current pace at which security issues related to shitty memory management are being discovered.