Unsafe C Functions: Secure Coding Strategies for Modern C and C++

Added:

Unsafe Copy
Safe Methods
Print Fixes
Token Safety
Scan Safety

Unsafe Copy

0:00
Playing Section
  • 1

    Identifies buffer overflow risks in string handling functions.

  • 2

    Shows how strcpy and strcat ignore buffer sizes. This can crash the system.

  • 3

    Introduces safe alternatives that respect buffer limits as the first fix.

A solid understanding of C/C++ memory management, specifically the difference between the stack and the heap.
Familiarity with pointer arithmetic and how C-style strings (null-terminated character arrays) function in memory.
A basic conceptual understanding of what memory corruption and buffer overflows are, including their general security implications.
Experience using standard, potentially unsafe C library functions like strcpy, sprintf, and strcat in basic programming tasks.
Transitioning to modern C++ abstractions, such as 'std::string', 'std::string_view', and standard containers, to eliminate manual memory management.
Integrating static and dynamic analysis tools (such as Clang-Tidy, cppcheck, and AddressSanitizer) into the build pipeline to automatically flag unsafe functions.
Studying industry-standard secure programming guidelines, such as the SEI CERT C and C++ Coding Standards.
Exploring operating system and compiler-level defenses against memory exploits, including Stack Canaries, ASLR (Address Space Layout Randomization), and DEP/NX (Data Execution Prevention).
Learning secure API design principles to write custom, robust libraries that resist misuse by other developers.
64.6K views3.6Klikes9:26@DavesGarageOriginal Release: 2023-01-09

This video explains that common C runtime functions like strcpy, strcat, sprintf, scanf, and strtok are unsafe because they don't respect buffer sizes and can cause memory corruption. The safe alternatives are strncpy_s, snprintf_s, scanf_s, and strtok_s, which properly handle buffer sizes and null termination. In C++, using string classes and stringstream provides even safer memory management.