4 ms·
> Most of today's programming problems come down to laziness and fear of "premature optimization" (which is obviously bunk). It is possible to write perfect C c
by pcwalton 11y ago
> Most of today's programming problems come down to laziness and fear of "premature optimization" (which is obviously bunk). It is possible to write perfect C code that runs correctly the first time and every time. You do that by planning ahead. Formal specs are part of this.
If "planning ahead" were enough to prevent security vulnerabilities in practice, someone would have done it by now. Instead, we've had C for upwards of 30 years and everyone, "bad programmers", "good programmers" and "10xers" alike, keeps introducing the same vulnerabilities.
It's a nice theory, but we've been trying for over 30 years to make it work, and it keeps failing again and again. I think it's time to admit that C as a secure language (modulo the extremely expensive formal coding practices used in avionics and whatnot) has failed.
- hyc_symas 11y agoSorry, but your statement makes no sense. That's like saying "we've been trying for over 5000 years to make hammers work, and people keep smashing their thumbs and fingers again and again. I think it's time to admit that hammers as a safe tool have failed." Security is not a property of the tool, it is a property of the tool's wielder.
- pcwalton 11y ago> Security is not a property of the tool, it is a property of the tool's wielder. How many memory safety bugs do you see in Java applications compared to C applications?
- hyc_symas 11y agoIf Java memory safety is so good, why does NullPointerException still exist in the language?
- pcwalton 11y agoI'm not talking about NPE (though I would be happy to elaborate on how not having null pointers also reduces crashes in the wild). I'm talking about exploitable and/or non-type-safe memory safety problems. Writing in Java is an effective way to reduce remote code execution vulnerabilities over writing in C. Statistics have shown this over and over again.
- hyc_symas 11y agoThe very fact that NPE exists, in a language which doesn't have pointers, running on a JVM that doesn't have pointers, is evidence that the entire model of "doesn't have pointers" is a sham. The reality of computer architecture is that data resides in memory, memory is an array of bytes, and bytes have addresses (i.e., pointers) and denying this fact is impossible. Even in a pure pointerless system like Java. And if there are pointers in the system, somewhere, anywhere, they are exploitable. Remote code execution vulnerabilities in C are less a feature of the language syntax and mostly due to the abysmally poor C library, which is regrettably part of "C The Language" - but no one forces you to use it - there are better libraries. Also, it's an artifact of implementation - just as Java's supposed immunity is an artifact of implementation, not an inherent feature of the language syntax. Case in point http://www.trendmicro.com/vinfo/us/threat-encyclopedia/vulnerability/7033/oracle-java-se-remote-code-execution-vulnerability-cve20152590 http://www.trendmicro.com/vinfo/us/threat-encyclopedia/vulne... As for RCEs in C code - these would be easily avoided if the implementation used two separate stacks - one for function parameters, and one for return addresses. If user code can only overwrite passive data, stack smashing attacks would be totally ineffective. Again - there's nothing in the C language specification that dictates or defines this particular vulnerability. It is solely an internal implementation decision.
- pjmlp 11y agoReferences are pointers.
- pcwalton 11y ago> As for RCEs in C code - these would be easily avoided if the implementation used two separate stacks - one for function parameters, and one for return addresses. No. Increasingly, RCEs are due to vtable confusion resulting from use after free.
- hyc_symas 11y agoSounds like you're the one with confusion; vtables are not a feature of C. C++, sure, but that's a different conversation. Your point is invalid.