Secure Coding in C and C++

Secure Coding in C and C++ is a two day training course that provides a detailed explanation of common programming errors in C and C++ and describes how these errors can lead to code that is vulnerable to exploitation.

    This course concentrates on security issues intrinsic to the C and C++ programming languages and associated libraries. You will learn to identify common security flaws including:

    • Memory safety
    • Insecure Integer operations
    • Undefined behaviors

    For each of these security flaws, we demonstrate specific remediation techniques as well as general secure coding practices that help prevent the introduction of vulnerabilities.

    Material in this presentation was derived from the Addison-Wesley books Secure Coding in C and C++ and The CERT C Secure Coding Standard.


    Day 1: Strings

    1. Introduction
      1. Standards
      2. Conformance
      3. Behaviors
      4. Errors
    2. Common errors using NTBS
      1. improperly bounded string copies
      2. null-termination errors
      3. truncation
      4. write outside array bounds
      5. off-by-one errors
      6. improper data sanitization
    3. Common errors using basic_string
    4. String Vulnerabilities
      1. Program Stack
      2. Buffer Overflow
      3. Code Injection
      4. Arc Injection
    5. Exercise: Identify String Problems
    6. Mitigation Strategies
      1. Prevention Strategies
      2. Detection Strategies
    7. Summary

    Day 2: Integers

    1. Integer Types
      1. Integer Data Types
        1. Unsigned integer types
        2. Wraparound
        3. Signed integer types
        4. Signed integer ranges
        5. Overflow
        6. Character types
        7. Other integer types
      2. Integer Conversions
        1. Integer conversion rank
        2. Integer promotions
        3. Usual arithmetic conversions
        4. Conversions to unsigned integer types
        5. Conversions to signed integer types
        6. Conversion implications
      3. Integer Operations
        1. Addition
        2. Multiplication
        3. Division/remainder
        4. Right shift
      4. Exercise: Reviewing Code for Integer Defects
        1. Integer Vulnerabilities
        2. Wrap around
        3. Conversion error
        4. Truncation
        5. Non-exceptional
      5. Mitigation Strategies
        1. Integer type selection
        2. Safe integer operations
        3. Compiler Strategies
        4. Testing and reviews
      6. Summary
    2. Dangerous Optimizations
      1. Compiler Optimizations
      2. Constant Folding
      3. Adding a Pointer and an Integer
      4. Integer Overflow
      5. GCC Options
      6. Volatile
      7. Strict Aliasing
      8. Optimization Suggestions
      9. Null pointer
      10. Uninitialized Reads
      11. C11 Analyzability Annex
      12. Summary and Recommendations

    Who should attend

    Secure Coding in C and C++ should be useful to anyone involved in the development or maintenance of software in C and C++.

    • If you are a C or C++ programmer, this book will teach you how to identify common programming errors that result in software vulnerabilities, understand how these errors are exploited, and implement a solution in a secure fashion.
    • If you are a software project manager, this book identifies the risks and consequences of software vulnerabilities to guide investments in developing secure software.
    • If you are a computer science student, this book will teach you programming practices that will help you to avoid developing bad habits and enable you to develop secure programs during your professional career.
    • If you are a security analyst, this book provides a detailed description of common vulnerabilities, identifies ways to detect these vulnerabilities, and offers practical avoidance strategies.


    The course assumes basic C and C++ programming skills, but does not assume an in-depth knowledge of software security. The ideas presented apply to various development environments, but the examples are specific to Microsoft Visual Studio and Linux/GCC and the Intel Architecture.

    Software to install

    Students are also encouraged to bring their own C and C++ programming language development environments (compiler, editor, etc.), such as Microsoft Visual Studio, Xcode, GCC, or Clang.

    Robert Seacord
    Standardization Lead

    Robert C. Seacord is the Standardization Lead at Woven Planet he works on the Software Craft. Robert was previously a Technical Director at NCC Group, Secure Coding Manager at Carnegie Mellon's Software Engineering Institute, and an adjunct professor in the School of Computer Science and the Information Networking Institute at Carnegie Mellon University.

    He is the author of seven books, including Effective C: An Introduction to Professional C Programming (No Starch Press, 2020), The CERT C Coding Standard, Second Edition (Addison-Wesley, 2014) Secure Coding in C and C++, Second Edition (Addison-Wesley, 2013), and Java Coding Guidelines: 75 Recommendations for Reliable and Secure Programs (Addison-Wesley, 2014). He has also published more than 50 papers on software security, component-based software engineering, Web-based system design, legacy-system modernization, component repositories and search engines, and user interface design and development. Robert has been teaching secure coding in C and C++ to private industry, academia, and government since 2005. He started programming professionally for IBM in 1982, working in communications and operating system software, processor development, and software engineering and also has worked at the X Consortium, where he developed and maintained code for the Common Desktop Environment and the X Window System. Robert is on the Advisory Board for the Linux Foundation is an expert at the ISO/IEC JTC1/SC22/WG14 international standardization working group for the C programming language.

    Programutvikling uses cookies to see how you use our website. We also have embeds from YouTube and Vimeo. How do you feel about that?