The CERT C Secure Coding Standard
securecoding.cert.org
securecoding.cert.org
Learn a new thing every day.
There was a Usenix talk on developing code for Mars rovers in which Gerard Holzmann pointed out that for large projects coding standards are much more effective when you have automated compliance checking. https://www.usenix.org/conference/hotdep12/workshop-program/...
I note that there is a tool for checking the CERT rules called Rosecheckers: http://www.cert.org/secure-coding/tools/rosecheckers.cfm? It looks like it might be incomplete and/or outdated.
And the CERT pages include a reference to a deleted summary of other automated checkers such as Coverity and Klockwork: https://www.securecoding.cert.org/confluence/display/seccode...
I've been recently trying to learn Ada and it's a beauty. Many people have misconceptions or think it's obsolete so they miss out.
The problem is that they were tied to OS that weren't successful in the mainstream, whereas some American startups using the original BSD code and AT&T licenses, got very successful and brought UNIX into the enterprise.
C came along of course.
I wonder if that kind of coding standards can be part of ISO standards.
Many developers think that they don't need static analyzers.
Actually lint was part of the original UNIX, but since it took some effort to configure and not everyone agreed with the rules, it was seldom ported to other systems, and it became part of the C culture not to use it.
I think we have to thank the LLVM project that now static analyzers are welcome in C.
Basically, the CERT rules all must be analyzable (though some require dynamic analysis instead of static analysis).
The rules specified in this Technical Specification apply to analyzers, including static analysis tools and C language compiler vendors that wish to diagnose insecure code beyond the requirements of the language standard. All rules are meant to be enforceable by static analysis.
I wrote an article putting all this in some context at: http://www.informit.com/articles/article.aspx?p=2088511
See https://www.securecoding.cert.org/confluence/display/seccode... and exception EXP05-EX3 in particular.
Exception promotes non-standard-compliant (undefined) behavior because it "usually works".
More information on the distinction can be found at: https://www.securecoding.cert.org/confluence/display/seccode...
Not only C, but the other CERT standards as well.
Java luckily doesn't suffer from use after free, out of bounds, stack corruption, return oriented programming, dangling pointers.
A memory safe language is still open to parameter validation, races to data access in external resources, validation of external data, incorrect use of security certificates, configuration exploits and many more.
Getting rid of C style bugs is only the tip of the iceberg in security.
just don't.
somewhere.I understand why a standard like this is necessary, but really it's like a CERT Safe Highway Cycling Standard or a CERT Healthy Smoking Standard. If security is an important enough goal to want to apply this entire standard in detail, maybe there are better options than C.
Hopefully this won't still be true in 10 years. Hopefully. But I was hopeful about that 10 yers ago.
For performance, the type-safe SPARK Skein implementation (http://www.adacore.com/press/spark-skein/) matches the C implementation, after the optimizer phases in the compiler were matched up. While doing the translation from C, they even uncovered a bug in the C implementation.
Anecdata, sure, but that's mostly a popularity issue.
http://www.mikroe.com/mikropascal/
http://www.mikroe.com/mikrobasic/
For more beefy systems,
In embedded, there may be other language choices for coding "close to the metal", but they are rarely used, time-costly to work with, and often not well-supported for all platforms. Most micro-controller vendors supply their board-support packages (BSPs) in C, and choosing some other family of (higher level than assembly) language can result in some rather high development costs with few if any benefits in terms of code space or system efficiency.
Not to mention many higher-level languages (and, at least, their compilers or interpreters) are implemented in C (or C++) - Ruby, Python, Lua, etc. Even if one works on desktop applications or web development, C has importance, very likely, at some level in the technology stack.
Those that dismiss C either misunderstand the importance and ubiquity of it as a language and/or inadvertently expose their prejudice towards development at higher levels of abstraction. In any case, C is very likely here to stay, good to know well, and good to know how to code more securely.
C/C++ is likely fine for e.g. games programming where speed is of maximum importance and security/verifiability is not.
However in 2015 I would not write nor recommend others write new system services (e.g. DNS, DHCP, web servers, etc) in C or even C++. They're insecure by design and as history has shown us, they cannot be made secure.
That all being said, as there is a massive code base of pre-existing code it is often impractical to not continue these projects in C/C++. It would require tens of years of work to do so. However if an OpenSSL replacement was written in a more secure language with verification being a priority from the ground up, I'd be all over that like a cat on tuna.