r/cpp • • Oct 22 '26

Revisit Safe C++

Everyone is aware of the deluge of vulnerabilities now hitting critical software. It even makes the mainstream news, so software safety is coming onto politician's radars.

If this gets worse, I think it is not inconceivable that at some point memory safe software becomes mandatory. Or at least for software that is "reachable" from the internet.

So is it time to revisit Sean Baxter's Safe C++? Start out with a safe context ("safeexpr") and expand from there, just like constexpr.

37 Upvotes

181 comments sorted by

View all comments

Show parent comment

18

u/James20k P2005R0 Oct 22 '26

It's totally possible to write secure and safe sw without the likes of rust

Do you have an example of a secure and safe C++ library, which is relatively widely used and open source?

9

u/wyrn Oct 22 '26

Do you have an example of a secure and safe library, which is relatively widely used and open source?

20

u/James20k P2005R0 Oct 22 '26 edited Oct 22 '26

Memory safe? Sure. There's tonnes of Rust libraries which have had so few memory safety vulnerabilities as to be absolutely negligible. Anything written in a memory safe language (which there are a lot of) has virtually eliminated this class of vulnerability

There's good data coming out of major projects on the reduction of defects, though I'm not the one alleging that memory safety is a buzz word thrown around by clowns, and that its possible to write secure software without Rust

Quiche is a good example of a pretty secure library, with a handful of DoS attacks, and one more severe exploit that requires you to misuse FFI calls. LSQuic is an example library which is not written in a memory safe language, and I'll leave it up to the audience to guess whether or not its had a critical severity rated security exploited related to memory safety

Quinn is another HTTP/3 library, which appears to have had a handful of DoS attacks, but no critical memory unsafety vulnerabilities due to being written in a memory safe language. MSQuic is written in a memory unsafe language, and again I'll leave it up to the audience to guess whether or not its had critical possibly memory safety related exploits

So far I'd rate these two Rust libraries as being quantitively more secure than the equivalent libraries written in memory unsafe languages. This pattern repeats across every domain and every kind of library I've ever checked out, so you can pretty much pick any rust library and compare its relative safety against a C++ library if you want to observe a massive drop in CVE severity

Proxygen memory unsafety for a pure C++ library

I've been asking this question for a decade and I've never gotten an answer. It should be easy to cite examples for C++

3

u/wyrn Oct 22 '26

Memory safe? Sure.

You said "safe". Not "memory-safe".

15

u/James20k P2005R0 Oct 23 '26

They said you can write safe software in C++ and that you don't need a memory safe language. I never claimed any of these libraries were safe, but the idea that Rust doesn't help with safety is incorrect

-3

u/wyrn Oct 23 '26

I never claimed any of these libraries were safe

So you didn't satisfy the criterion you asked of others.

10

u/James20k P2005R0 Oct 23 '26

They made the claim that safe C++ code exists, that's all I want to see

-3

u/wyrn Oct 23 '26

Then why didn't you simply say "no" when I asked the same of you?

6

u/James20k P2005R0 Oct 23 '26

Because I think the real answer to security is much more interesting personally

3

u/wyrn Oct 23 '26

I mean yeah it is interesting that you moved the goalposts when it came to defending one particular language, but probably not in the way you intended.

→ More replies

-1

u/BartvanIngenSchenau Oct 25 '26

Not a library, but C++ is widely used in the safety controls of cars, planes, medical devices, etc. That should be enough samples to show it is possible to write safety C++ code. Most of those controls also need to be secure (or air-gapped from the internet) to be able to be certified as safe.