Does using Rust really make your software safer?

51 points by folkertdev


alandekok

Using almost anything other than K&R C makes your program safer.

FTA:

  • The tools used to write software don’t help prevent mistakes, and in fact make it hard to detect them if they have been made.

  • External input is implicitly trusted instead of being explicitly validated.

I’ll address the second item first.

We have ~350K LoC, all C. Everything builds with no warnings. We use multiple static analysis tools. We use fuzzers to test the portions of the code which face the network. We use assertions everywhere. We’ve written internal functions to sanity check data structures.

It might crash due to some internal oversight or state machine illogic. But we’re pretty darn sure it’s safe. We never trust input from anywhere. This is a design decision, and a habit.

For the second item, Rust is “better than C” because of its tooling. Rust prevents bad patterns which C allows. This makes the code safer. The Rust compilers also do more / better checks for safety than are done by the C compilers.

The result is a safer program. But nothing prevent a Rust program from reading the network (safely), connecting to an SQL server (safely), and then using the network data unchecked in SQL queries. We then have the “little Bobby Tables” issue.

In order for Rust to be safe_r_, it should also allow constructs which catch and complain about those kinds of errors, too.