News for hackers. Stuff that matters.
Re:Programming Languages as Constraints by btrask on Friday June 03, 2016 @03:03PM (#11832437)
Okay, libraries can't provide new inabilities. But that's why we have linters, static analyzers, style guides, compiler options and warnings, and ultimately code reviews and good taste.

I think the big problem (and sometimes benefit) of old languages is their culture. For example, C programmers don't trust anything written since K&R. This is both good and bad. Creating a new language doesn't force existing communities to change; it means creating a new community and either waiting for the old ones to die off, or (ideally?) driving them into obsolescence.

I remember when Wikipedia was new and there were lots of studies finding errors in their articles. Instead of replacing Wikipedia, those techniques for finding errors were simply incorporated into the editing process (as much as possible). I wish that as new classes of bugs came onto our radar, we could go back and refine old code instead of throwing it out with the bathwater. (Even OpenSSL wasn't beyond saving, judging by BoringSSL and LibreSSL. These projects still need more work, of course.)

Re:Programming Languages as Constraints by akkartik on Friday June 03, 2016 @03:48PM (#11832739)
"For example, C programmers don't trust anything written since K&R."

That is an incredibly broad generalization. Perhaps you were implicitly assuming some qualifiers? :)

---

"..that's why we have linters, static analyzers, style guides, compiler options and warnings.."

But all those things are still just glorified retrofits on the job of the language. Are there any examples where a new library in a new domain adds inabilities that weren't originally enforced (or even conceived of) in the language?

One example I can think of is reading/writing files. The original C had simple numbers for file descriptors, which meant that in a large application you might try to read from a write-only fd, or vice versa. The C++ standard library solved that by creating separate types for istreams and ostreams. No reason we couldn't apply that idea to C as well.

On a tangent, I'm fascinated by the fact that Go hasn't bothered to steal that idea. For example, a goroutine can read or write any of the channels it has access to. If you try to juggle too many at once, that might cause the odd typo bug. It'll be interesting to see if source/sink channel types ever get retrofitted to Go in a decade or so.

Re:Programming Languages as Constraints by mw42 on Friday June 03, 2016 @05:17PM (#11833338)
> It'll be interesting to see if source/sink channel types ever get retrofitted to Go in a decade or so.

Channels can be designated as receive-only or send-only in variable and function declarations:

  ch := make(chan int, 1)
	
  var send chan<- int = ch
  var recv <-chan int = ch

  send <- 1 // ok
  <- recv   // ok

  recv <- 1 // invalid operation: recv <- 1 (send to receive-only type <-chan int)
  <- send   // invalid operation: <-send (receive from send-only type chan<- int)
Re:Programming Languages as Constraints by akkartik on Friday June 03, 2016 @05:21PM (#11833360)
Ah! Can't believe I missed that..
Re:Programming Languages as Constraints by scott_s on Friday June 03, 2016 @03:40PM (#11832680)
And yet with those, we still have security vulnerabilities in C programs. That, I think, is a strong argument for languages which have very specific constraints. (For example: Rust.)
Re:Programming Languages as Constraints by NoIdeaAtAll on Saturday June 04, 2016 @12:50AM (#11834952)
Do you have any idea how much software is run behind a firewall? If someone is even able to run my software that means they have full access to a shell and compilers for multiple programming languages. As such, there are much easier ways to run malicious code than to exploit a buffer overflow in my C or C++...

So really, your argument only applies to public facing servers or web browsers. Unless you're writing one of those, I think your argument is weak.

Re:Programming Languages as Constraints by MaulingMonkey on Saturday June 04, 2016 @02:25AM (#11835216)
> So really, your argument only applies to public facing servers or web browsers.

Or, you know, literally anything touching a file format that might be downloaded. PDFs, word documents, images, zip files, movies, music, sounds, icons that show up in your file explorer, user profiles, any sort of web client (email, games, chat, wget, package managers, ...) lots of poison apples out there.

This kind of nonsense is why the best advice to handling USB drives you find on the ground is to toss them in a fire barrel - everyone thinks they're "behind a firewall" and that they're totally protected! They have all the protection of a wet tissue in a hurricane.

Oh, but I'm just writing a terminal! I don't touch file formats! It's safe to auto-execute commands in response to pasted newlines! ...and then you've helped enable the spread of malware through clipboard hijacking Javascript. Oops.

Firewalls are not a panacea. Firewalls are a roadbump.

> Unless you're writing one of those, I think your argument is weak.

I think your security is borderline nonexistent. I think I cannot trust you with C. I think someone is probably in your systems if you're in charge of the security side of IT, of anywhere of significance, unless you delegated enough responsibility to make you a figurehead.

I mean no offense by this. A lot of reasonably talented and smart programmers make the same mistake as you, and go write a bunch of exploitable vulnerabilities in C as a result. It's not like you're one of those madmen disabling ASLR, NX, stack cookies, or some of the many other mitigation techniques being used to try and clean up after this tragedy of our times. ...right?

Re:Programming Languages as Constraints by NoIdeaAtAll on Saturday June 04, 2016 @12:15PM (#11836816)
> I think I cannot trust you with C.

You really don't get it, but your arrogance is overwhelming. I don't care who you trust.

> I mean no offense by this.

Yes you do.

Re:Programming Languages as Constraints by MaulingMonkey on Saturday June 04, 2016 @05:39PM (#11838216)
> You really don't get it

Then point out what I'm missing.

Re:Programming Languages as Constraints by NoIdeaAtAll on Sunday June 05, 2016 @02:23AM (#11839885)
Look, you're just another arrogant novice who runs around telling people how to be safe so you can convince yourself that you're safe. Maybe you'll grow out of that, or maybe you'll stay obnoxious forever. I doubt you want an actual answer, and I'm pretty certain you don't deserve one.

However, giving you the benefit of the doubt - There tens of thousands of programmers out there (myself included) who write software to analyze data. We don't make "apps" for users, and we don't download random PDFs or MP3s for input. Your view is so limited, you can't even imagine software that isn't a product or a tool for advertising, but trust me - a lot of software is written in other environments, and malicious users or malicious data is not a real concern.

Anyways, don't bother to reply. I'm sure you won't admit you're wrong, and I'm not interested in continuing this discussion.

Re:Programming Languages as Constraints by dllthomas on Sunday June 05, 2016 @05:06AM (#11840209)
As a third party to this discussion, you really need to check your attitude and up the charity a few notches. I was finding the conversation interesting but for wading past all the time you spent typing while avoiding communicating.
Re:Programming Languages as Constraints by MaulingMonkey on Sunday June 05, 2016 @04:53AM (#11840187)
> However, giving you the benefit of the doubt

I appreciate that.

> There tens of thousands of programmers out there (myself included) who write software to analyze data. We don't make "apps" for users, and we don't download random PDFs or MP3s for input. Your view is so limited, you can't even imagine software that isn't a product or a tool for advertising, but trust me - a lot of software is written in other environments, and malicious users or malicious data is not a real concern.

Ahh. It's funny - you think I can't think of all the software where security isn't an issue, and I think you can't think of all the software where security is an issue.

I'm aware that there is software where, rightly, security isn't a huge concern. It exists. Some software for crunching data internally counts! And some software is written where the front door is wide open anyways. But the scope for software where security isn't a concern sure as shit isn't "everything but public facing servers or web browsers", as I took you to imply. It's also not "everything but products and advertising tools". Point of sales systems, industrial control software, internal financial software, routers, telecom infrastructure... all kinds of wonderful "internal", bespoke systems, that most definitely need to care about security and protection against malicious users, or malicious employees. Industries where mandatory vacations are a security policy against fraud, where your software will be generating audit logs, where defense in depth matters against external threats even if you could trust your employees.

Which are just chock full of C programs. Sigh.

> I'm not interested in continuing this discussion.

Fair enough. Thank you for taking the time you did.

> Look, you're just another arrogant novice who runs around telling people how to be safe

Yeah, probably. Not so arrogant as to be certain I can think of every reason my software might actually need to care about security, or to try and write security critical C in good conscious, though.

> so you can convince yourself that you're safe.

I'd never succeed at that. Safer, maybe, but never safe.

> Maybe you'll grow out of that, or maybe you'll stay obnoxious forever.

For the sake of progress and a safer future, let's hope for the latter.

Re:Programming Languages as Constraints by catnaroek on Friday June 03, 2016 @08:31PM (#11834251)
> But that's why we have linters, static analyzers,

Which tend to be based on heuristics, rather than any sort of rigorous foundation. There's no shortage of static analysis tools for C and C++ that reject good code and accept bad code.

> style guides,

Which can be very onerous, limiting your ability to define useful abstractions, leaving you with just the bad parts of the base language (e.g., Google's C++ Style Guide).

> compiler options and warnings,

No amount of compiler options or warnings will force you to use an abstract type, well, abstractly, in a language that has unrestricted memory access (C and C++), unrestricted reflection (Java, .NET, anything dynamic), or both (some Common Lisp implementations).

> and ultimately code reviews and good taste.

If only the latter weren't in short supply...

Re:Programming Languages as Constraints by nostrademons on Friday June 03, 2016 @04:51PM (#11833189)
Re:Programming Languages as Constraints by akkartik on Friday June 03, 2016 @05:09PM (#11833296)
Re:Programming Languages as Constraints by andrepd on Friday June 03, 2016 @04:15PM (#11832924)
>C programmers don't trust anything written since K&R.

C is one of the most used languages in the world, and the number of programmers is surpassed perhaps only by a handful of languages. That alone tells me any generalisation you make about C programmers is most probably erroneous.

Re:Programming Languages as Constraints by pjmlp on Friday June 03, 2016 @05:32PM (#11833413)
Not everyone uses C willingly.
Re:Programming Languages as Constraints by nickpsecurity on Friday June 03, 2016 @07:40PM (#11834036)
"COBOL is one of the most used languages in the world, and the number of lines of code is surpassed perhaps only by a handful of languages. That alone tells me any generalisation you make about COBOL programmers is most probably erroneous."

One a name and one phrase changed but it's still technically true. Clearly something wrong with your argument unless you think COBOL is also superior to other languages due to uptake.

Re:Programming Languages as Constraints by golergka on Friday June 03, 2016 @08:02PM (#11834132)
Comment you're replying to didn't say anything about C being superior or not.
Re:Programming Languages as Constraints by nickpsecurity on Friday June 03, 2016 @08:26PM (#11834234)
It implied it had good design or worth vs other languages due to massive uptake vs other languages.
Re:Programming Languages as Constraints by KMag on Friday June 03, 2016 @10:35PM (#11834651)
My reading of the OP was just that there are tons and tons of C programmers, who almost certainly use C for many different reasons, and it's hard to believe any sweeping generalisation of such a large diverse group.... and therefore it's difficult to believe that none of the large and diverse number of C programmers trust anything after K&R.
Re:Programming Languages as Constraints by andrepd on Saturday June 04, 2016 @01:59AM (#11835140)
Yes, that was what I meant to say. Nowhere, of course, did I say anything about C being good or not.
Re:Programming Languages as Constraints by nickpsecurity on Saturday June 04, 2016 @06:00AM (#11835730)
In that case, I take it back.
Re:Programming Languages as Constraints by drabiega on Friday June 03, 2016 @03:33PM (#11832632)
Well, a lot of the point of these constraints is to reduce complexity, as the writer mentions. When you add constraints with most of those tools, you're actually adding complexity to your tooling, build process, and cognitive load if not to your actual code base.