Secure Coding: Buffer Overruns Flashcards
(60 cards)
What is a buffer overrun?
A programming error where data exceeds a buffer’s capacity, overwriting memory.
When did buffer overruns first appear?
1960s, notably exploited by the 1988 Worm.
What is the impact of a buffer overrun?
Can cost millions if systems are compromised.
Why are C and C++ prone to buffer overruns?
Allow direct memory manipulation, increasing error risk.
What is a buffer in programming?
A contiguous memory block holding multiple instances of one data type.
What is a C++ span?
A lightweight abstraction for a contiguous sequence of values in memory.
What does a C++ span contain?
A pointer to data and a length, with convenience methods.
What is std::string_view in C++?
A view of a string defined elsewhere, avoiding copies.
What are std::string_view’s benefits?
Good performance, observes strings without copying.
When did Microsoft create secure C string functions?
2002, later part of C11 Annex K and ISO/IEC WDTR 24731.
What is an example of a secure C string function?
strcat_s(dest, size, src).
What is OpenBSD’s equivalent to strcat_s?
strlcat.
What is gcc’s equivalent to strcat_s?
strncat(to, from, size).
Why is char *gets unsafe?
Reads from stdin until CR/LF, risking buffer overflow.
What should replace char *gets?
fgets or C++ stream objects.
What is a static solution for buffer overruns?
Use strncpy, strlcpy, or strlcat.
What is a dynamic solution for buffer overruns?
Use C++ std::string or SafeStr library.
Why avoid std::string’s data() or c_str()?
Extracting C strings can reintroduce buffer overrun risks.
What is a stack overrun?
A buffer on the stack is overrun, overwriting the function’s return address.
What causes a stack overrun?
Unchecked user input in functions like strcpy().
What can an attacker achieve with a stack overrun?
Execute malicious code, like binding a shell to a port.
What is a static buffer overflow?
Another term for stack-based buffer overflows.
Why fix all buffer overrun bugs?
All are potentially exploitable, even if not proven.
What is a heap overrun?
Writing data beyond a heap-allocated buffer’s bounds.