Live data from Hacker News

The CERT C Secure Coding Standard

securecoding.cert.org

31–32 of 32 posts

Re: The CERT C Secure Coding Standard

#31

I investigated this Standard once. 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".

BudVVeezer and bgtnhz have already made some of my points for me. "EXP05-C. Do not cast away a const qualification" is a recommendation largely because casting away constness isn't undefined behavior. There is a also a rule "EXP40-C. Do not modify constant objects" which defines a normative requirement not to modify constant objects which would result in undefined behavior. The intent of the exception to EXP05-C is to let authors of API constrain how objects of types they expose can be used by users without forcing the same constraints on the implementation. In C++, this can be done by making class members private and providing inline member functions. In C, the options are using opaque types (which has a performance cost because they can only be accessed by non-inline functions defined in the implementation's .c files), or making the struct pointer members const and casting the const away in inline functions. This is safe because the implementer knows that the objects the const pointers do not point to const objects (because the implementation initialized them). We're considering getting rid of the exceptions and risk assessments for recommendations because it suggests that conformance to recommendations is required.

Re: The CERT C Secure Coding Standard

#32
post #6

I'm well aware this is full-on "middlebrow dismissal", but still, I feel that in 2015 this standard isn't complete without a chapter saying 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…

Two use cases where C is often the only choice are OSes and micro-controllers.

Indeed. C (and, to a limited degree C++) are natural choice(s) for embedded and low-level development.

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.

Post reply on HN