Re:Would Rust have prevented Heartbleed? Another look
by stream_fusion on Tuesday March 17, 2015 @05:55PM
(#9221841)
Almost all languages have an escape-hatch to do dangerous stuff.
The key insight about Rust is the set of programming abstractions (linear types to manage resources) that enable one to get systems-like programming tasks done, without needing to fall back on very low-level coding techniques.
Re:Would Rust have prevented Heartbleed? Another look
by jonesetc on Tuesday March 17, 2015 @04:53PM
(#9221371)
> That's of course a bit glib.
I think you mean it's a bit glibc.
Re:Would Rust have prevented Heartbleed? Another look
by Rickasaurus on Tuesday March 17, 2015 @05:31PM
(#9221665)
What about adding safer checked buffer types as part of the standard library? A fixed buffer for things of "up to this size" where it remembers how big the current thing is.
Seems like it would be a pretty easy problem to fix if you're not playing fast and loose.
Re:Would Rust have prevented Heartbleed? Another look
by steveklabnik on Tuesday March 17, 2015 @05:35PM
(#9221697)
That's what Vectors, slices, and arrays already do. See that v.len()?
Re:Would Rust have prevented Heartbleed? Another look
by latiera on Tuesday March 17, 2015 @09:00PM
(#9222850)
Oh but it DOES mean that Rust has no value, at least regarding security. Once you give them the rope, they WILL use it. Let's see if time will prove me right.
Re:Would Rust have prevented Heartbleed? Another look
by kibwen on Tuesday March 17, 2015 @10:10PM
(#9223175)
Every language has a C FFI that users can use as rope to hang themselves with. `unsafe` code in Rust is just a reified FFI that actually manages to make Rust code safer because it means fewer things need to be written in C, and even unsafe Rust code is safer than C. Furthermore, the strict demarcation of `unsafe` blocks greatly alleviates the burden upon code auditors, allowing them to focus their efforts. Even if an extraordinarily high percentage of your code is contained within unsafe blocks, say 10%, that's ten times less code to audit than an equivalently-sized C codebase.
Re:Would Rust have prevented Heartbleed? Another look
by nnethercote on Tuesday March 17, 2015 @10:59PM
(#9223332)
You remind me of a guy I once knew who reasoned that because type systems could not prevent all bugs, they were useless.
"Half a hole is still a hole," he said smugly.
"But it's a much smaller hole," I replied.
Re:Would Rust have prevented Heartbleed? Another look
by Dewie on Tuesday March 17, 2015 @07:50PM
(#9222483)
> Hi. Rust core here.
I for one am ready for my daily Rust PR programming.
[dead]
Re:Would Rust have prevented Heartbleed? Another look
by kibwen on Tuesday March 17, 2015 @10:04PM
(#9223143)
What an incredibly useless and demeaning comment. Everyone who has used Rust has needed to be corrected at times because of the changing nature of the language over the past few years, including people on the core team. When Steve has needed to be corrected he takes it graciously, and I say this as someone who has corrected Steve before. As for "extrinsic ethos", not only does HN make it trivial to gloss over usernames but most people do not expect members of a language's core team to come forward with frank explanations of its limitations.
If you have problems with Steve, this is not the place to air them.
I like to say that of course Rust prevented Heartbleed, because we don't currently support wrapping malloc ;). That's of course a bit glib.
While it's true that Rust gives you a lot of assistance with writing safe code, given that unsafe exists, and that we, as a systems language, need to give you underlying access to the machine, Rust will allow you to do all kinds of stupid things if you vouch to the compiler that you're going to handle the safety aspect. This means that ultimately, you can do any kind of stupid thing in Rust that you can do in any other language.
An example: a common problem in C code is buffer overflows, which happens when some code thinks that an array has more elements in it than it does. Because C's arrays don't have a length as part of the type, it can be error prone to keep track of the length of the array. Rust's arrays, vectors, and slices all have a length as a part of the type, and so it's more difficult to have this data be out of sync. But Rust will let you be stupid if you want to:
The `bad_stuff` function here uses `get_unchecked()`, which skips the array bounds check, to grab some memory past the length of the end of the vector. Rust will happily compile this code, your `unsafe` block tells the compiler to trust that you're using `get_unchecked()` in a safe way, even though it can't verify it.Now, there's a decent discussion that can be had on this topic: 'usual' Rust code will of course be significantly safer than 'usual' C code, since you have the compiler's assistance. Unfortunately, security is often about the edge cases. While it's true that not wrapping malloc would have prevented Heartbleed from happening, and most C projects don't wrap malloc... it did happen. Once Rust starts getting used in the wild, we'll see Rust with security problems, I'm sure of it. That doesn't mean that Rust has no value, just that we need to be realistic about the tradeoffs that any of our technologies make. Rust is not a panacea, even if it does cure some of your aches and pains.