Hacker News new | ask | show | jobs
by throwaway894345 26 days ago
> While it is very difficult to write perfectly safe code in C, this seems to be used as explanation for the amount of CVEs we see. But when I look at the CVEs, the code is often terrible!

Given the choice between a language that requires expert coding for minimal safety guarantees and one which can tolerate human error, I’ll take the latter all else equal. Also, given that experts feel they can’t write correct C reliably, I’m inclined not to think I can (never mind contributors).

> At the same time, the Rust rewrite of coreutils with more than 100 CVEs does not exactly convince me that the problem is mainly the choice of language.

I’m not a Rust fanboy, but I don’t know what I should make of this. Is 100 CVEs a lot for coreutils? If the idea is “Rust doesn’t preclude all CVEs therefore language choice doesn’t matter”, I don’t think that follows.

> Still, I think there also many obvious benefits from using C.

The only I can think of are that the toolchain—but not the compiled programs—-can run on niche hardware (minor benefit), that bootstrapping may be easier, and that the toolchain may be more performant (although Go compiles faster than most C-based toolchains I’ve seen, so I’m inclined to think the language matters less here than the compiler design itself).

1 comments

> Given the choice between a language that requires expert coding for minimal safety guarantees and one which can tolerate human error, I’ll take the latter all else equal.

Again, I do not believe this is true. One gets a reasonable level of safety with only basic measures even in C. In practice, memory safety is also not even remotely the main issue to worry about, especially when writing a compiler.

> Also, given that experts feel they can’t write correct C reliably, I’m inclined not to think I can (never mind contributors).

It is not easy to write correct code in any language. See the number of CVEs in the Rust rewrite of coreutils or generally the number of issues one also sees in Rust projects (including still memory safety issues.) If at all, this means that the C experts are not naive about it.

> Again, I do not believe this is true. One gets a reasonable level of safety with only basic measures even in C.

Even if you believe this is true and the experts are wrong, other languages don’t require even these “basic levels” to provide a greater degree of safety, so presumably they’re still the better choice if only for this reason (not to mention all the others).

> In practice, memory safety is also not even remotely the main issue to worry about, especially when writing a compiler.

I agree—but those other concerns (e.g., attracting developers) are overwhelmingly reasons not to use C.

> It is not easy to write correct code in any language

Right, but “impossible” and “not easy” are different, right?

> See the number of CVEs in the Rust rewrite of coreutils

How are we supposed to derive anything from this? The 44 Rust rewrite CVEs were the result of a comprehensive professional audit that Canonical paid for and which the coreutils project has never experienced. Moreover the coreutils project predates CVE trackers. If your point is “Rust doesn’t preclude logic errors”, then who are you arguing with?

> including still memory safety issues

Which of the 45 or so CVEs were memory safety?

Many C experts I know would not agree with this. What experts are you quoting?

I do not understand your comment about "impossible" and "not easy". It is not impossible to write correct code but also not easy - in any language.

The audits of Rust uutils which identifies 113 issues in total confirm exactly what I said: It is not easy to write correct code in any language, and also in Rust it is very easy to make stupid errors that can compromise safety and security.

My comment about memory safety was about Rust CVEs in general, not uutils. For example, https://rustsec.org/advisories/ lists more than 20 use-after-frees for 2026.