7 ms·
I too love C. I'd almost go so far as to say you need to do a security review before you write one line of code. You need to evaluate if C is a requirement or
by Someone1234 11y ago
I too love C.
I'd almost go so far as to say you need to do a security review before you write one line of code. You need to evaluate if C is a requirement or a preference, and if the security of the project can withstand being written in C (e.g. edge code that may be attacked).
The argument that C (and C++) can be written well or flawlessly is tiresome. "Perfect code" is a fallacy that has been proven over and over again to be untrue and dangerously untrue. You should assume the code quality is less than optimal as your starting point.
I am not promoting any specific alternative (Rust, Java, Go, etc) I am just saying that C/C++ are insecure by design and should be avoided unless they're a project requirement.
- robert-wallis 11y agoThis sounds like a witch hunt. Java has horrible security bugs even today. Bugs can be found in code written in all languages.
- iso-8859-1 11y agoJava removed certain classes of errors (memory management). It introduced other (providing an insecure sandbox for applets).
- swsieber 11y agoRight. And certain languages remove entire classes of bugs.
- Someone1234 11y agoNo disputing that bugs can be written in any language. But by avoiding C/C++ you're excluding a specific class of bugs which have historically proved harmful. You can write exploitable code in Java. But you'd actually have to try if you wanted Java to be able to write arbitrary memory or execute arbitrary code. Essentially any bug that can be written in Java/Go/Rust/etc can be written in C/C++. But some C/C++ bugs are extremely uncommon in other languages, or you have to actually TRY to introduce them.
- ArkyBeagle 11y agoIntent doesn't matter; results do. This is a heatmap problem - there's simply more 'C'/C++ code out there.
- hansjorg 11y agoI'm pretty sure there is more (and a greater variety of) net facing Java code than C/C++ code.
- ArkyBeagle 11y agoYou may be right. I'm just thinking that everything( has an O/S and it's probably written largely in 'C'. So much will depend on how you measure it. I tend to ignore the web as much as possible.
- shanemhansen 11y ago> But you'd actually have to try if you wanted Java to be able to write arbitrary memory or execute arbitrary code. Depends on your definition of arbitrary. Higher level languages have higher level exploits. While injecting x86 shellcode into a java process is probably hard, many java applications have been vulnerable to serialization bugs which result in the execution of arbitrary bytecode. Source: http://www.darkreading.com/informationweek-home/why-the-java-deserialization-bug-is-a-big-deal/d/d-id/1323237 http://www.darkreading.com/informationweek-home/why-the-java...
- 11y ago
- gr3yh47 11y ago>Bugs can be found in code written in all languages. But not all languages frequently produce security vulnerabilities as a result of common types of bugs that are due to error-prone humans having to do things that should be done for us automatically in the year of our Lord 2016
- Sindisil 11y agoTo be clear, are you referring to security bugs in the Java standard library (written almost completely in Java), or those in the JVM itself or the browser plugins (written almost entirely in C++), or in Java code bases? The vast majority of the high profile Java security bugs have been in the second, which would be more of a ding against C++ than Java the language, wouldn't it?
- geodel 11y agoI think it would be against Java in sense Java does not support writing high performance code like Java runtime / security code etc. Now it may not have errors as much as openssl but that argument will be about implementation quality not against C/C++.
- tveita 11y agoMost the horrible security bugs in Java show up in the sandbox, where attackers can supply arbitrary code for you to run. In contrast, Java as a server language has an excellent security record IME. The last public patch panic I can remember was in 2011 with the denial of service bug regarding parsing of floating points. There has been other security bugs regarding cryptography etc, I'm sure, but in general you can feel very secure running Java on your servers. It is a shame that security bugs for both are bundled together, making every sandbox compromise a "Remote exploitable" vulnerability. The "applet" use case should probably just die, there is no indication that Java sandboxing will ever be secure, the design is unsound.
- hansjorg 11y agoOracle is deprecating the Java browser plugin in JDK 9, ie. the applet use case. There will still be support for Java Web Start though.
- ThisIs_MyName 11y agoI've always wondered why nobody sandboxes Java applets in a LXC/Docker container or in a chrome sandbox the same way flash is contained.
- makomk 11y agoJava as a server language has a record of nasty serialization-related RCE vulnerabilities. Of course, they're in popular Java libraries used on the server rather than the language itself, just like this bug was in a popular C library rather than the language itself - but Java makes it very easy to accidentally write that kind of vulnerability. In fact, just loading two unrelated libraries that are individually safe sometimes create an exploitable RCE condition in Java. That's worse than even C.
- _Codemonkeyism 11y agoNot sure what 'horrible security bugs' in Java you are referring too. If those you refer too, and there are many, are exploits in browser plugins, sandboxes or the JVM, these are written in C(++).
- cstejerean 11y agoJava applets have security issues today. That's a situation where you are allowing random websites to execute arbitrary code on your computer. Flash has the same issues. So don't do that. Don't confuse Java applets (and the lack of security thereof) with the JVM as a development platform. I'd bet on the security of a Java application over that of a C/C++ application any day.
- lmm 11y ago> Java has horrible security bugs even today. Example? > Bugs can be found in code written in all languages. And there's no difference between a bug every week and a bug every 10 years?
- robert-wallis 11y agoHere's a list of Java CVEs: https://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-19117/Oracle-JRE.html https://www.cvedetails.com/vulnerability-list/vendor_id-93/p... To be clear, I am not a security researcher, and I haven't verified the severity of these issues. But in 2016 alone there are 16 CVEs which is 4 per month.
- lmm 11y agoThose are vulnerabilities in the JVM itself - and I'd bet a fair bit the majority will be in the C/C++ parts, not the Java parts.
- pcwalton 11y ago> Bugs can be found in code written in all languages. This is like saying "there's no point building bridges because sometimes they collapse". Memory safety bugs are found far, far less often in memory-safe languages.
- zzzcpan 11y agoTo be fair, most of the vulnerabilities found in C codebases are preventable with static analysis, bound checking, etc. If you are ok with it getting as slow as Go, you can get similar safety guarantees as well.
- nickpsecurity 11y agoYou can get complete spatial and temporal safety with Softbound + CETS: http://www.cs.rutgers.edu/~santosh.nagarakatte/softbound/ http://www.cs.rutgers.edu/~santosh.nagarakatte/softbound/ They and Cambridge CHERI team have hardware modifications, too, if you want to run C apps on FPGA CPU with inherent safety. Software-only, though, has significant performance penalties.
- lmm 11y ago> To be fair, most of the vulnerabilities found in C codebases are preventable with static analysis, bound checking, etc. You can work in an ad-hoc dialect of C based on particular tools that will be a bit safer than standard C, sure (though probably still not as safe as an actually memory-safe language). But at that point most of the advantages of C no longer apply: you don't have a huge library ecosystem, you don't have a supply of experienced developers, you don't have a bunch of standard automated tools that work with your dialect. > If you are ok with it getting as slow as Go, you can get similar safety guarantees as well. There is no native/standard/supported-by-tools way to do tagged unions, so whatever you do C will always be less safe than languages that have native tagged unions.
- jjnoakes 11y agoI don't think "most of the advantages of C no longer apply [if you use static analysis or bounds checking]" is fair. Even if your claims about losing libraries, experienced developers, or automated tools was true (which think is false), you still get portability, close-to-the-metal code, full control of your processes, direct access to the native ABI, full access to the platform facilities, fast compilation, small executables, standalone libraries, memory layout control, ...
- 0xdeadbeefbabe 11y agoprintf("bull crap"); short programs can be secure.
- Scea91 11y agoC++ is vastly different animal than C in this case. Most of the problems with C you are implying here are non issues in modern C++.
- Someone1234 11y agoThe key being modern C++. A lot of C++ projects aren't written in modern C++ and out of the few that are, even then, programmers will mix in older less secure C++ because they lack experience with modern C++. So habits can actually hurt security. Ultimately when you have a language which mixes secure and insecure practises and lets the programmer decide, as an outside observer you have to assume the worst unless shown otherwise. C++ can be written very well, but C++ can also be written no better than C, it is project by project for which is which. Other languages don't have this issue. If you see a Rust, Go, Java, C#, etc block of code you can make certain assumptions about what classes of security issues it won't have.
- oconnore 11y agoYou're saying exactly the same thing. "This environment can shoot me in the foot, but not if I do it right." MISRA C with copious static analysis and a talented QA team is safe, too!
- steveklabnik 11y agoWeb browsers use modern C++ and still have security issues. It's a step forward, but not a panacea.
- abiox 11y agoto what extent? i imagine the codebases are quite...mature. and gigantic.
- pcwalton 11y agoEverywhere. We have been using smart pointers for a long time. Modern C++ doesn't add any memory safety protection beyond that which was already available with custom smart pointers in earlier versions of C++. In fact, I think modern C++ is less safe than earlier versions, due to new classes of potential bugs like use-after-move and the ease with which closed-over variable references in lambdas can become dangling.
- ArkyBeagle 11y agoIt may be tiresome, but it happens to be true. That something isn't done is not evidence than it cannot be done. I think 'C'/C++ is the scapegoat for a massive cultural failing and have thought that for going on 25 years now.
- seangrogg 11y agoYeah, it's possible to write flawless code. The problem is that it doesn't happen in practice. You know, where people are actually relying on this code that "could be flawless but isn't" so they can run businesses, maintain privacy, etc.
- mokus 11y agoI'd say C is more of a symptom and exacerbating factor of the cultural failing. C makes it easy to achieve performance and time-consuming to achieve correctness. When the people funding the work (and this includes people donating their own time) can see performance issues but not correctness issues, guess which ones get fixed?
- ArkyBeagle 11y agoThere is absolutely no doubt in that. But people also join the Marines, so.... I'll speak this heresy - I think "people donating their time" has a bunch of problems, not least of which losing the data/information that would be gained from pricing that labor.