News for hackers. Stuff that matters.
Re:Drop-In Replacement for Memcached by vlmutolo on Sunday December 12, 2021 @05:35PM (#29534399)
The "goto fail" bug isn't a great example; Rust actually does specifically guard against this by requiring curly braces around the body of "if".

Here's an explanation of "goto fail", which includes a code snippet.

https://nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-got...

If C conditionals required explicit braces around the body, the second fail would have been redundant code instead of a security vulnerability.

Additonally, Rust will warn you if you have "unreachable" code, such as all the code after the unconditional "goto fail". Though, I'm sure modern C compilers would also warn about this.

All that said, Rust definitely does have plenty of bug classes left for people to trip over. Integer under/overflows come to mind (though they're just logic errors instead of undefined behavior).

Re:Drop-In Replacement for Memcached by tialaramex on Sunday December 12, 2021 @05:57PM (#29534569)
In the same class as the integer over/underflows, Rust also doesn't warn for throwing away information when casting. So (my_value as u16) might be a completely safe transformation from an unsigned one byte my_value to a u16, but it might be throwing away the top 16-bits of a 32-bit value and Rust doesn't think that's worth any additional caution.

Rust also hasn't boarded the "People can't remember precedence rules" train like some modern languages. It has fewer operators with unnecessary values, reducing some opportunities for mistakes like C's increment footgun, but it does still have precedence and so you can still forget the precedence rules which the compiler is going to apply to your code.

But there are a lot of things Rust does catch, and there are even more things that aren't caught by Rust the language per se but are caught in idiomatic Rust because the language affords better ways to do things. Locking is an example, idiomatic Rust locking means you can't make the lock A but change B mistake seen so often in real bugs, because idiomatic use of Rust's type system would put the variable B inside the lock for B, if you didn't take the lock you don't have the variable to change it. https://doc.rust-lang.org/std/sync/struct.Mutex.html

Re:Drop-In Replacement for Memcached by Vecr on Sunday December 12, 2021 @11:42PM (#29536693)
You can enable Clippy lints for `as` casting, and I think some of the common "throwing data away" ones are caught in the standard configuration or just pedantic. https://rust-lang.github.io/rust-clippy/master/index.html#as...
Re:Drop-In Replacement for Memcached by pjmlp on Monday December 13, 2021 @02:22AM (#29537508)
Another example would be bounds checking, yes it is much better than silenty corrupting memory, but dying with a panic might not be the best solution in some cases, specially if the application is controlling hardware.

Not only Rust, this applies to all safe languages, just crashing also opens the door to exploits and denial attacks.

Re:Drop-In Replacement for Memcached by tialaramex on Monday December 13, 2021 @04:14AM (#29538019)
If the bounds check fails at compile time then the program doesn't compile. This seems like it should be a reasonable ask for any programming language, but, apparently not.

And it probably applies to all general purpose languages but of course it doesn't apply to all the safe languages that aren't general purpose. You can't have bounds misses in WUFFS. When you try to touch array[x] in WUFFS, the compiler constrains the type of x to have a boundary limit according to the size of the array, reasoning that you can't very well have meant for it to be possible to overstep the bounds of the array at runtime. Trivial arithmetic mistakes you might find in unit testing or worse production with other languages are often compile time errors in WUFFS as a result.

Re:Drop-In Replacement for Memcached by pjmlp on Monday December 13, 2021 @04:24AM (#29538083)
Except bounds checking fail at runtime like 90% of the time.
Re:Drop-In Replacement for Memcached by tialaramex on Monday December 13, 2021 @07:17AM (#29538890)
Well, like I said, in WUFFS this literally can't happen, WUFFS doesn't have any concept of runtime bounds checking, likewise it has no runtime overflow/underflow checking, if the compiler can't see why what you're doing will obey the constraints you don't have a valid WUFFS program at all (well, library, WUFFS is a special-purpose language so you're not going to go around writing whole programs in WUFFS)

And it's still a pretty sad indictment when a compiler is looking at your access, can see it's outside the boundaries and doesn't reject the program because the language (e.g. C) wasn't defined with this obvious expectation.

For me it's in the same category as the (now fixed in an errata) behaviour where as I understand it C++ 20 std::format didn't consider it a compile time error if you wrote

  format("check X: {} Y: {} and Z: {}", x, z)
... even though that's obviously an error, and it's obvious you can detect it at compile time, the original specification said nah, this code just blows up at runtime, good luck with that.
Re:Drop-In Replacement for Memcached by pjmlp on Monday December 13, 2021 @07:28AM (#29538958)
How would you write random app X? That is my point, I don't care about special niche cases.
Re:Drop-In Replacement for Memcached by tialaramex on Monday December 13, 2021 @04:02PM (#29544617)
I think a lot of people would already consider the cases you've declared to be relevant - where dying due to bounds failure is unacceptable - to be niche cases which need to do their own work to stabilise and not act like this is everybody else's problem. It isn't, for example, as if explicitly checking bounds isn't possible in Rust if you want to do something other than give up.

For example I would consider it acceptable if feeding badly corrupted MP3s to the MP3-capable CD-radio makes it stop working... until I disconnect the power and restart it. Nobody dies, if it's very annoying I should remove the offending MP3 file. Whereas if it causes random mayhem that's a problem because now troubleshooting is impractical and most likely the apparent solution is to replace the entire device.

And remember that such "turn it off and on again" is considered acceptable even in some systems you probably deem safety critical, so long as it needn't happen when actively dangerous. For some years trains in the UK with a beacon-based safety system couldn't handle waking up next to a beacon, their firmware wanted to start by not seeing a beacon, then encounter beacons while travelling - so waking up next to one was confusing and they'd go into an error state. The fix? Mostly "don't park the train there when it's to be switched off", but when it happened inadvertently, they would move the train a few metres with its safety systems disabled, turn the power off, wait a few seconds, turn the power back on and no longer able to see a beacon it was now happy.

Re:Drop-In Replacement for Memcached by pjmlp on Monday December 13, 2021 @04:31PM (#29544934)
That is where I disagree, when you buy a pair of shoes that are somehow uncomfortable to wear, do you live with the pain or go to the shop to exchange them?

Exactly that is what we are missing in the software industry, the niche cases of high integrity computing should be a common practice, just like most people usually don't put up with broken stuff when given the option.

We need more liability not less.

Re:Drop-In Replacement for Memcached by tialaramex on Monday December 13, 2021 @06:54PM (#29546345)
When I buy new boots they're uncomfortable for at least a week or two. Replacing the boots wouldn't help at all, the boots adapt to your feet and your feet adapt to the boots, I don't have money to get tailor-made boots that would fit to the millimetre on day one if that's even a thing -- which I suspect in fact it is not (that is, people who could afford such boots don't actually spend hours every day walking and so probably wear shoes which are comfortable but less effective).

User experience matters, and actually just dropping dead in error cases makes for a better user model than many outcomes. The user has a model of what the machine does, which is always over-simplified and often plain wrong, but it's vital to try to get to a place where the user's model doesn't contradict how it's actually to be used. Undefined Behaviour is the enemy of this outcome. The user definitely does not have a correct model of what Undefined Behaviour will be, as we see many programmers don't either, whereas "If I do this particular dumb thing, it stops working and I need to unplug it and start over" fits in the user model relatively well.

Computers aren't special in this regard, watch "Sully" (Miracle on the Hudson), the cockpit dialog is roughly correct. What does their QRH tell them to do in the event of dual engine failure? Turn the engines off first and then try turning them back on again. Didn't work because their engines were trashed, but if even one engine had restarted, those QRH instructions mean there would be no film, just a scary incident some passengers tell stories about and an aviation safety file somewhere, the plane climbs (slowly) on one engine, they're still an emergency but they can put it back down on a runway at their leisure.

Re:Drop-In Replacement for Memcached by pjmlp on Tuesday December 14, 2021 @02:04AM (#29549038)
Some people miracously avoid death by not wearing a seat belt, yet the statistics prove wearing it is still a much better option.