News for hackers. Stuff that matters.
Re:Getting Past C by jdmichal on Tuesday January 03, 2017 @05:16PM (#13313678)
Obviously, one can program C to do anything, and write all the provably safe abstractions wished. But, that's not really the point. The point is that doing such is not the default. It requires engagement and knowledge of the programmer, especially on distributed projects with loose communication, such as many open source projects. And it only takes one programmer mistake to bring the whole house of cards down.

Why allow programmers to make mistakes? That was fine in the 70's when resources for compiler execution were limited. I don't see any reason for it today.

I mean, just look at the underhanded C contestants and especially winners for ways in which your program can completely blow up for extremely subtle reasons.

Re:Getting Past C by pjmlp on Tuesday January 03, 2017 @06:20PM (#13314234)
Even in the 70's there were better alternatives outside AT&T walls, e.g. at Burroughs.
Re:Getting Past C by panic on Tuesday January 03, 2017 @05:18PM (#13313696)
And it only takes one programmer mistake to bring the whole house of cards down.

Isn't this also true of Rust, with its unsafe keyword? None of these languages are completely safe against programmer mistakes.

Re:Getting Past C by mrsteveman1 on Tuesday January 03, 2017 @05:56PM (#13314038)
> Isn't this also true of Rust, with its unsafe keyword?

> None of these languages are completely safe

No, but the first time I encountered an unexplained segfault in Rust was the first time I've ever found & fixed the cause of a weird segfault message in just a few minutes, because the mistake was in the 12 lines I had written inside a clearly marked unsafe block rather than the other ~3000.

Without something like unsafe blocks, finding known bugs and auditing code for other "weird" memory issues means looking much wider (and often, screaming "what the hell are you talking about?!" at the screen on a routine basis).

Re:Getting Past C by jjnoakes on Tuesday January 03, 2017 @05:52PM (#13313999)
You are equating the unsafe keyword in Rust with entire C codebase.

Yes, carelessness in either could amount to trouble. No, they are not close to the same amount of risk because the relative amount of code in each is orders of magnitude different, and unsafe blocks can be heavily reviewed.

Re:Getting Past C by dbaupp on Tuesday January 03, 2017 @05:55PM (#13314027)
This is true of every language: e.g. Python has ctypes, Haskell has Foreign, Java has JNI, etc. It's a matter of defaults/conventions rather than something being literally impossible to screw up.
Re:Getting Past C by staticassertion on Tuesday January 03, 2017 @05:27PM (#13313773)
Totally. But in the case of rust your vulnerabilities are grep'able. For all of the code you have in a project you only have to search for the unsafe keyword when you want to audit it.

I think that makes a very significant difference.

Re:Getting Past C by jdmichal on Tuesday January 03, 2017 @05:30PM (#13313802)
That's less of a mistake, and more of turning off the footgun's safety. Yes, it still only takes one programmer. But they have to purposefully enable such actions, as opposed to neglect to perform actions through the "proper" abstractions.
Re:Getting Past C by sidlls on Tuesday January 03, 2017 @05:27PM (#13313778)
Yes. It's trivial in Rust to write unsafe code. It's less trivial to mask the unsafe code and the (unproven, in my opinion) argument is that the explicit "unsafe" keyword makes it prohibitively difficult.
Re:Getting Past C by afarrell on Tuesday January 03, 2017 @05:25PM (#13313760)
Is the use of the unsafe keyword a default? I don't know Rust, but from a user interface perspective, it sounds like it has an affordance of "Hey! Pay particular attention to this bit because it is risky!"
Re:Getting Past C by Manishearth on Tuesday January 03, 2017 @06:25PM (#13314258)
It's more of a "Hey, trust me here when I say that the enclosed code is actually safe" hint to the compiler.

It's used sparingly. Not as sparingly as I'd like, but sparingly enough.

Re:Getting Past C by afarrell on Tuesday January 03, 2017 @07:10PM (#13314523)
Sure, but code is not just instructions to a compiler, but is also a user interface.
Re:Getting Past C by Manishearth on Tuesday January 03, 2017 @07:11PM (#13314531)
Oh, yes, as a UI it is "be extremely wary of this code" Often folks write long comments around unsafe code explaining why it is safe. Not always, sadly.
Re:Getting Past C by steveklabnik on Tuesday January 03, 2017 @05:34PM (#13313836)
It is very much not the default.
Re:Getting Past C by EugeneOZ on Tuesday January 03, 2017 @06:17PM (#13314212)
Even without `unsafe` programmer can make mistakes in Rust. Logical mistakes are unstoppable.
Re:Getting Past C by userbinator on Tuesday January 03, 2017 @10:04PM (#13315343)
Why allow programmers to make mistakes?

For a philosophical counterpoint: Why allow anyone to do anything that might possibly be incorrect, harmful, or otherwise perceived by some to be negative?

I've looked at a lot of the talk surrounding "safe/secure languages", "safe/secure programming", etc., and yet every time I've heard people preach about the benefits, I feel like I just vehemently disagree. At a very deep and fundamental level, I feel like somehow we are sacrificing something more important in the pursuit of this "safety", this seemingly overpowering desire to make everything completely safe, mindlessly constricted, and stifling. It's not just software; the whole "war on terrorism" irks me in the same way. I imagine a "completely safe" world, the ones these "safe software" proponents appear to be striving for, would be rather dystopian.

A quote that immediately comes to mind is: "Freedom is not worth having if it does not include the freedom to make mistakes."

Re:Getting Past C by caconym_ on Wednesday January 04, 2017 @01:58AM (#13316228)
People rely heavily on software in many aspects of their lives. They entrust it with their personal information, their money, and in many cases their physical safety. Engineers building software and companies selling it are ethically obliged to make a good faith effort to prevent defects that might betray their users' trust and cause harm. Languages designed to enhance the safety and security of software written in them are one tool that can be used in this effort.

Are engineering standards for public buildings evil because they stifle architects' freedom to design whatever crazy structures tickle their fancy? Should power tools not include safety features like blade guards because their users' freedom to accidentally kill or maim themselves must be held sacrosanct? Probably to both questions, the reasonable answer is "no".

If you're building something for yourself, and offer it to others only with clear warnings, then go nuts and make all the mistakes you want. Nobody's saying you can't do that; that sounds rather dystopian, a society where pointer arithmetic is illegal! But you can't treat a project people are meant to trust and rely on as your personal art project.

Re:Getting Past C by userbinator on Wednesday January 04, 2017 @06:05AM (#13317217)
Are engineering standards for public buildings evil because they stifle architects' freedom to design whatever crazy structures tickle their fancy?

The physical analogy is good because even there one can see that there are different standards --- and, unlike what the "safe software" community seems to promote, engineers are not doing the equivalent of making every building strong enough to withstand a nuclear war and calling anything less "unsafe".

This also brings up another difference with software: the "absoluteness". In the physical world, no security is perfect. Locksmiths exist, and with enough determination, essentially anything can be broken into. But in the software world, with good encryption, that can never occur. Provably correct software can be employed for effectively unbreakable DRM and un-rootable/jailbreakable user-hostile devices, of which there is (fortunately) no similar real-world analogy I can think of.

Nobody's saying you can't do that; that sounds rather dystopian, a society where pointer arithmetic is illegal!

Given that there are attempts at even prohibiting Turing-completeness[1][2], I would not be surprised if that eventually happens. As it is, I'm sure there are already people who would consider you suspicious if you write software in an "unsafe" language, and from there it is not far to complete prohibition.

"The road to hell is paved with good intentions."

[1] http://boingboing.net/2012/08/23/civilwar.html

[2] http://boingboing.net/2012/01/10/lockdown.html

Re:Getting Past C by caconym_ on Wednesday January 04, 2017 @01:28PM (#13320756)
So... you're saying it's unethical to invent tools that can be used to write software that works as intended and contains no exploitable bugs, because that software could then be used as a tool of oppression?

You can extend that absolutist argument to say that inventing anything that could be used as a tool of oppression is unethical. Like, inventing plumbing may have done great things for human society, but it was ultimately unethical because when the police came to take away your general-purpose computer they used a pipe to hit your kneecaps until you told them where it was. Or, how about this: developing any society beyond the level of the most primitive hunter-gatherer tribe is unethical, because what are governments if not the agents of oppression themselves?

This is the sort of abstract position that can't really be argued with in a vacuum, so I'm not going to try. But it's also not a useful ethic for building a modern society free of large-scale oppression, because it completely ignores the practical realities of doing so.

In the mean time, buggy, exploitable software is out there in the real world hurting real people every day.

Re:Getting Past C by jdmichal on Wednesday January 04, 2017 @09:44AM (#13318607)
> ... making every building strong enough to withstand a nuclear war and calling anything less "unsafe".

Yes. Except the equivalent in software is using something like Coq, where your intention is proven to be correct. (You even mention provably correct software in the next paragraph...) And yes, it would be awesome if we could prove every program, because all we would be doing is proving that the programmer's intent is correctly coded into the software, which doesn't limit freedom of expression at all. (I would argue that such is actually an even stronger form of expression, as it's afterwards impossible to misconstrue your intent.)

> Given that there are attempts at even prohibiting Turing-completeness[1][2], I would not be surprised if that eventually happen...

Rust is not one of these, and no one but you seems to have this in mind. So it's a bit of a strawman to be throwing it out here, no? But yes, obviously such a language would limit your freedom of expression.

Re:Getting Past C by jdmichal on Wednesday January 04, 2017 @09:30AM (#13318517)
Except we're not talking about limiting your freedom of expression. I'd challenge you to give me an example of a program that you can't express in Rust, with the obvious exception of silly and obviously unsafe things like "read from a random memory address". Which, by the way, was deemed so unsafe that the operating system itself will probably kill that program dead. (I can think of one excellent answer off the top of my head that requires `unsafe`.)

We're talking about eliminating a class of programmer error through static analysis. (If you're writing a large C program, you arguably should be using static and runtime analysis tools on it anyway.) This is no different than using a strong type system. Yes, it limits your "freedom", but sending a "banana" to a `sine` function is nonsense anyway. Well, it also ends up that reading 10 bytes into a five byte array is also nonsense, and we now have tools to detect that nonsense and tell you that it is, in fact, nonsense.

Re:Getting Past C by rtpg on Wednesday January 04, 2017 @02:27AM (#13316367)
You can still be clever in Rust. You just have to try harder and explicitly say "I'm trying to be clever" here. You might make a mistake, of course. But if you need it, the option is there.

There is no philosophical beauty in typos or off by one errors. You are not being stifled when your compiler points out to you that, no, "coutn" is not a variable currently in scope. If we have a static proof that what you just did will never work, why would you still want to do it?

And if you had a reason, you still have a way to do it.

If you're trying to be clever, you need to prove that you know what you're doing.

Re:Getting Past C by burntsushi on Tuesday January 03, 2017 @10:21PM (#13315408)
That's a great quote, and it's one that Rust---as a a memory safe language---completely embraces. You have the freedom to do anything you want. Some of those things simply require you to type "unsafe."
Re:Getting Past C by pekk on Tuesday January 03, 2017 @11:41PM (#13315734)
Forgive me for being cheeky, but just as Rust requires you to type "unsafe," C also requires you to opt in by typing "cc".

My serious point is that in practice, the example of C shows that if it is available and people understand that it is "performant" then you will see it all the time, including in libraries you are forced to use.

Re:Getting Past C by burntsushi on Wednesday January 04, 2017 @08:56AM (#13318243)
> Forgive me for being cheeky, but just as Rust requires you to type "unsafe," C also requires you to opt in by typing "cc".

This isn't an accurate analogy at all because I can compile thousands of lines of Rust code without even thinking about needing to use `unsafe`. How many lines of C code can you compile without `cc`?

> My serious point is that in practice, the example of C shows that if it is available and people understand that it is "performant" then you will see it all the time, including in libraries you are forced to use.

Except this is already demonstrably false in the Rust ecosystem.

Re:Getting Past C by Sean1708 on Wednesday January 04, 2017 @01:05PM (#13320524)
Well sure if you compile your C one statement at a time, somehow I doubt you do though.
Re:Getting Past C by srean on Tuesday January 03, 2017 @10:39PM (#13315478)
"UNIX was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things."
Re:Getting Past C by Retra on Tuesday January 03, 2017 @11:57PM (#13315794)
Freedom is not worth having if you squander it by making easily avoidable mistakes, either. The point is to make mistakes that lead somewhere. I.e., mistakes that we can't yet write programs to easily prevent.

And there is no shortage of mistakes available for you to make, so don't worry about that.

Re:Getting Past C by imtringued on Wednesday January 04, 2017 @05:01AM (#13316972)
There is no need for another unsafe fast language. There is also no need for another safe slow language. We already have enough of those. Rust's purpose is to find a middle ground between those extremes.