Home > Articles > Security > Software Security

Robert Seacord on the CERT C Secure Coding Standard

Robert C. Seacord and David Chisnall discuss the CERT C Secure Coding standard, developing C standards, and the future of the language and its offshoots.
Like this article? We recommend

Like this article? We recommend

I recently had the opportunity to interview Robert Seacord, author of the recently-published The CERT C Secure Coding Standard. Robert has been deeply involved with C and UNIX for longer than I've been programming in any language. Read on to find out about his work on developing C standards and his views on the future of the language.

David Chisnall: To get things started, could you give the readers a bit of background about yourself and what got you interested in secure coding?

Robert C. Seacord: I started working for IBM in 1984 in processor development (I was on the development team for S/390, among other projects). I was always interested in finding better ways to develop software, so I ended up joining the software engineering group at IBM and working on a graphical language editor written in C for the IBM PC. In 1987, I had an opportunity to join the Software Engineering Institute (SEI) where I worked on a user interface management system called Serpent. I left the SEI in 1991 to commercialize this technology, and eventually ended up at the X Consortium in Cambridge working on X11 and the Common Desktop Environment. When the XC shut its doors in 1996, I returned to the SEI and worked in the area of component-based software engineering.

I joined Computer Emergency Response Team (CERT) — which is part of the SEI — in 2003 as a vulnerability analyst. At the time, I had no idea I was interested in secure coding, but of course I had always been intrigued by the various properties of software (such as performance and portability) that are manifested by the coding choices we make. While I understood how to produce code that performed reliably under normal operations, I did not fully understand the exploits that could be launched against software and how code that appeared to be perfectly correct could be vulnerable to attack. After reading an (unpublished) technical report on the root causes of vulnerabilities, I recognized the potential for a disciplined approach to secure software development and consequently researched the material for Secure Coding in C and C++ (which was published by Addison-Wesley in September 2005).

DC: What motivated you to write a book on secure coding?

rCs: The CERT C Secure Coding Standard was the fourth book I've written, and the second on software security. The idea came up at the WG14 Berlin meeting in April of 2006 that the C programming community would benefit from CERT developing a secure coding standard. I immediately saw the wisdom of this proposal. The C99 standard is an authoritative document, but the audience for it is primarily compiler implementers and, as been noted by many, its language is obscure and often impenetrable. The CERT C Secure Coding Standard is geared towards C language programmers and provides actionable guidance on how to code securely in the language.

DC: A lot of people have given up on the idea of writing secure code in C and decided that the only solution is to modify the language, most commonly the memory model. What is your opinion on languages which try to be a safer C, like BitC and Limbo?

rCs: Secure coding in C poses some interesting challenges, but I think that the people who have given up writing secure programs in C are not maintaining huge code bases written in this language. I'm not an expert on either BitC or Limbo, and although the objectives of these languages appear admirable, it doesn't appear that either language address the legacy code issue. Another problem with these languages is that they are not industrial strength languages, meaning that the pool of skilled engineers available for these languages is small, there are a limited number of compilers available for a limited set of platforms, and there are fewer libraries available. The D programming language, on the other hand, is more widely used but is not strictly backward compatible with C source code.

A memory model for C1X is currently on the front burner of WG14.

When it comes to new development efforts, I have found that language choice is typically based on multiple criteria, and that security is rarely the determining factor.

DC: You've talked a bit about people maintaining legacy code bases, and one of the most well known examples in the open source world is one you were involved with near the start: X11. Do you think there are any lessons, good or bad, that other people with similar-aged codebases could learn from this project?

rCs: X11 and CDE were the best-managed software projects I've worked on, so there were many positive lessons. The X Consortium recruited highly competent, professional engineers and provided them with a well-defined, tool-supported development process. Because portability was a concern, we were required to test our code on multiple platforms before promoting the code. The thing that impressed me most, however, was that the management did not allow developers to get into a comfort zone. Defects were assigned based on availability and priority so we would frequently be asked to repair defects in components (and possibly languages) we weren't necessarily familiar with. At first glance, this might seem like a bad idea, but it kept the engineers sharp, engaged, and always learning. There was also a strong emphasis on quality, meaning that we were always given the time to do the job right.

DC: What other advice would you give to people maintaining a large, widely-deployed, aging, project?

rCs: The first thing to decide with an aging system is if you want to keep it running or if you want to replace it. Replacing an aging system can be an expensive and difficult process, particularly if you need to maintain continuous operations. To keep a system running, you need to allocate adequate resources to the project to support the continuous evolution of the software and include experienced software engineers on the project team. Many software defects, including defects which result in vulnerabilities, are introduced during maintenance, so it is important to maintain quality controls. Probably the most important thing during software evolution is to maintain the architectural integrity of the software. It is the beginning of the end for any system when you start to add features or capabilities to a system that are not supported by the architecture. Try to find time to perform preventative maintenance, and not just repair known defects or add new features to avoid an expensive modernization or replacement effort. (My second book, also published by Addison-Wesley, is on Modernizing Legacy Systems).

DC: You mentioned C1x a bit earlier. What is your connection with the standards process?

rCs: I am the CMU representative to INCITS PL22.11, the US committee contributing to ISO/ANSI C, and a technical expert at ISO/IEC WG14. At the WG14/INCITS J11 meeting in London, UK, April 2007 there was general agreement the committee should start thinking about what was next for a revision of the C Standard. At this same meeting, the original principles that were used for C9X were reviewed, and the observations was made that trust the programmer, as a goal, is outdated in respect to the security and safety programming communities and that the C1X version of the C Standard should take into account that programmers need the ability to check their work.

DC: What do you consider the most important proposed changes in the next version C standard?

rCs: From a safety and security perspective, I think the most important changes to C1X are those that improve the analyzability of C language programs and eliminate or reduce the impact of undefined behaviors. Many of these changes support the recommendations we have documented in The CERT C Secure Coding Standard. For example, I am working with other C language standard committee members to propose a normative but optional annex to C1X for "Error Checked" implementations. This annex would likely include the functions defined by TR 24731-1 (STR07-C. Use TR 24731 for remediation of existing string manipulation code), including the runtime constraint handling mechanism (ERR03-C. Use runtime-constraint handlers when calling functions defined by TR24731-1), as well as additional capabilities. For example, preventing run-time overflow by program logic is sometimes easy, sometimes complicated, and sometimes extremely difficult (INT30-C. Ensure that unsigned integer operations do not wrap, INT32-C. Ensure that operations on signed integers do not result in overflow). In many cases, the resulting code is much less efficient than what a compiler could generate to recognize that an overflow took place. We would like to propose that implementations which support this annex (for example, as a compiler option) would detect overflow when it occurs and report it by invoking a runtime-constraint handler before the subsequent return or function call operation. This should allow programmers and implementers to keep branches out of inner loops and not unduly impact performance. Another important change is the adoption of static assertion from the new C++ standard (see DCL03-C. Use a static assertion to test the value of a constant expression).

DC: C began life as the ultimate domain-specific language, being created to write one thing: UNIX. It grew in the '80s to be an incredibly widely-used general-purpose language, and has since had a lot of its market-share eroded by higher-level languages. Do you see C continuing to be viewed as a general-purpose language? If not, what niches do you see it continuing to serve?

rCs: Right now C is doing well in the embedded systems market. Unless something is done about software security in C, I expect to see the market for the language contract as developer's become less concerned with performance and more concerned with software security. I think The CERT C Secure Coding Standard is a good start, but we need better and cheaper source code analysis tools in the short term, and fundamental improvements to the language in the long term.

DC: On the subject of tools, are you familiar with the clang static analyzer? If so, what are your opinions on it?

rCs: LLVM/Clang static analyzer is a standalone tool that find bugs in C and Objective-C programs. It has potential for extensibility because it is based around a compiler framework, and appears to have a large community involved in support and development. At this time it seems to be pretty limited in the number of checks it does for C and the C++ support is quite unfinished. However, in some testing we've done it had a pretty low rate of false positives for those bugs that it can find.

DC: If you didn't have to worry about persuading the standards committee, what would you change about C?

rCs: I've supported a number of proposals for improving security in C. Some of these have been accepted, some have been shot down for good reason, and some are works in progress. Among the things we are working on is to add an 'x' mode character to the C99 fopen() and freopen() functions that cause fopen() to fail rather than open a file that already exists. This is necessary to eliminate a time-of-creation to time-of-use race condition vulnerability. I would also like to see something akin to the nonstandard clearenv() function that can be used to clear out the environment in an implementation-defined manner. This would ensure non-critical environmental values are removed, and critical environmental variables are set to default values. I would also like to see support for encrypted function pointers. In many systems and applications, functions pointers are stored unencrypted in locations where they can be overwritten. An attacker who can exploit a vulnerability to perform an arbitrary memory write (write an address to an address) can overwrite the function pointer and transfer control to arbitrary code when the function is called. Instead of storing a function pointer, the compiler can store an encrypted version of the pointer and decrypt the pointer before invoking the function. An attacker would need to break the encryption to redirect the pointer to malicious code.

DC: And if you were creating a new language without worrying about backwards compatibility, what would you do differently?

rCs: I actually created a new language some years ago called "Slang" for the Serpent User Interface Management System. Now that I'm older and more experienced, I don't think I would create another new language. Right now I'm more interested in fixing the ones we already have.

DC: Microsoft created "Managed C++" as a subset of C++ that could run in a typesafe virtual machine. Do you see a market for a "Managed C" that would be better suited to static analysis? If so, how would you go about designing such a language?

rCs: After completing Secure Coding in C and C++ back in September 2005, I spent some time researching C++/CLI (Common Language Infrastructure). At the time, it was difficult to generate verifiable components using /clr:safe because the available documentation was frequently unclear as to was valid for /clr:safe. In many instances I would find an example that was supposed to compile and run under /clr but would cause errors if used with /clr:safe. I did publish one article on this C++/CLI in May 2006 called Secure Coding in C++/CLI—Is buffer overflow still a problem? before I abandoned this work to focus on The CERT C Secure Coding Standard.

I guess I don't see a market for Managed C, primarily because C++/CLI never really seemed to take off, and because I think C users are even less likely to adopt a managed version of the language. I think there are better ways to accomplish the same goals, such as Safe-Secure C/C++ from Plum Hall.

DC: The vulnerability you mentioned, related function pointers, sounds like it could be mitigated by an operating system with write-xor-execute policies and completely avoided with a CPU that supports Mondrian memory protection. Are there any other features you'd like to see added in operating systems or instruction sets to make secure coding easier?

rCs: I think that Mondrian memory protection could potentially mitigate against arbitrary writes, depending on how it is implemented. For example, in the following code:

void good_function(const char *str) {...}
static void (*funcPtr)(const char *str);

funcPtr = &good_function;

Memory allocated to funcPtr needs to be writable at the time of the assignment but at no other time. Encrypting and decrypting of function pointers is currently performed by Visual C++'s C runtime libraries using the EncodePointer() and DecodePointer() functions. Currently, calls to these functions are manually inserted and are not automatically generated by the compiler.

The trend in adding runtime mitigations to operating systems is encouraging, and many of the current techniques are quite effective at raising the bar for exploit writers. Continuing the trend with randomization in even more places in the operating system (even when it doesn't mitigate currently known attacks) and the further reduction of privilege that various components run with are both features I would like to see promoted.

The instruction set question is an interesting one. This is unlikely to be the most critical change, but we recently discovered an interesting property of signed integer operations on the IA-32 instruction set. Dividing INT_MIN by -1 results in an overflow on any machine that uses 2's complement representation because the resulting value cannot be represented. The IA-32 idiv instruction generates a fault on interrupt vector 0 for any division error including overflow and divide-by-zero. What is even more interesting is the behavior of the % operator which is meant to calculate the remainder. The expression INT_MIN % -1 should result in the value 0 (the remainder when INT_MIN is divided by -1) but instead results in a fault because the idiv instruction is used to calculate the remainder. In fact, if you use the constant values as shown above the compiler will likely optimize your code and produce the correct value of zero. However, if you provide the values at runtime, the compiler will need to generate code to calculate the remainder, which will result in a fault. Although this could be viewed as a compiler bug, the consensus of WG14 is that this should be explicitly documented as undefined behavior meaning that any compiler that exhibits this behavior can still be considered conforming.

Robert C. Seacord began programming (professionally) for IBM in 1982 and has been programming in C since 1985 and in C++ since 1992. Robert is currently a Senior Vulnerability Analyst with the CERT/Coordination Center at the Software Engineering Institute (SEI). His most recent book, The CERT C Secure Coding Standard, can be found at InformIT and bookstores everywhere and in Safari Books Online.

David Chisnall, author of The Definitive Guide to the Xen Hypervisor (also available in Safari Books Online) and numerous articles on InformIT, is a research assitant at Swansea University and a founding member and core developer of the Étoilé project, which aims to build an open source user environment based for desktop and mobile computing systems.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020