Secure Coding: Buffer Overruns Flashcards

(60 cards)

1
Q

What is a buffer overrun?

A

A programming error where data exceeds a buffer’s capacity, overwriting memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When did buffer overruns first appear?

A

1960s, notably exploited by the 1988 Worm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the impact of a buffer overrun?

A

Can cost millions if systems are compromised.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why are C and C++ prone to buffer overruns?

A

Allow direct memory manipulation, increasing error risk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a buffer in programming?

A

A contiguous memory block holding multiple instances of one data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a C++ span?

A

A lightweight abstraction for a contiguous sequence of values in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a C++ span contain?

A

A pointer to data and a length, with convenience methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is std::string_view in C++?

A

A view of a string defined elsewhere, avoiding copies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are std::string_view’s benefits?

A

Good performance, observes strings without copying.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When did Microsoft create secure C string functions?

A

2002, later part of C11 Annex K and ISO/IEC WDTR 24731.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an example of a secure C string function?

A

strcat_s(dest, size, src).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is OpenBSD’s equivalent to strcat_s?

A

strlcat.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is gcc’s equivalent to strcat_s?

A

strncat(to, from, size).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is char *gets unsafe?

A

Reads from stdin until CR/LF, risking buffer overflow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What should replace char *gets?

A

fgets or C++ stream objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a static solution for buffer overruns?

A

Use strncpy, strlcpy, or strlcat.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a dynamic solution for buffer overruns?

A

Use C++ std::string or SafeStr library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Why avoid std::string’s data() or c_str()?

A

Extracting C strings can reintroduce buffer overrun risks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a stack overrun?

A

A buffer on the stack is overrun, overwriting the function’s return address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What causes a stack overrun?

A

Unchecked user input in functions like strcpy().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What can an attacker achieve with a stack overrun?

A

Execute malicious code, like binding a shell to a port.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is a static buffer overflow?

A

Another term for stack-based buffer overflows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Why fix all buffer overrun bugs?

A

All are potentially exploitable, even if not proven.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a heap overrun?

A

Writing data beyond a heap-allocated buffer’s bounds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Why are heap overruns serious?
Programmers may think they’re not exploitable, but they are.
26
What makes heap overruns harder to exploit?
Lack of direct control over critical memory like return addresses.
27
Why are tools for heap overruns limited?
Unlike StackGuard for stack overruns, similar tools are scarce.
28
Do heap overruns exist across OSes?
Yes, including Unix and Windows.
29
Why avoid writing user input to arbitrary memory?
Prevents exploitation via buffer overruns.
30
What are array indexing errors?
Writing to memory beyond an array’s bounds, similar to buffer overruns.
31
Are array indexing errors common exploits?
Less common than buffer overruns but still dangerous.
32
What are string format bugs?
Vulnerabilities in vararg functions like printf, leading to memory issues.
33
Why is printf(input) exploitable?
Allows format string attacks, unlike printf('%s', input).
34
When were string format bugs found?
In 2000 and 2001, in UNIX and some Windows apps.
35
What does C++20’s formatting library use?
{} delimiters instead of printf’s %.
36
What is a Unicode/ANSI buffer size mismatch?
Mixing element counts with byte sizes in Windows Unicode buffers.
37
What is an example of a Unicode buffer overrun?
Internet Printing Protocol (IPP) vulnerability (MS01-23).
38
How do Unicode functions handle buffer sizes?
In wide characters, not bytes, unlike ANSI.
39
How can buffer overruns be prevented?
Validate all inputs and isolate internal implementation.
40
What is offensive programming?
Expecting and handling erroneous input, possibly crashing the program.
41
When was offensive programming coined?
In a 1998 Usenet post.
42
What is exception handling?
Raising errors to propagate outside buggy code, isolating failures.
43
How does exception handling help?
Constrains failures to buggy parts, preserving system integrity.
44
What is an example of exception handling?
A word processor failing a printout without losing the document.
45
What is Visual C++ .NET’s /GS option?
Protects against simple stack overruns, similar to StackGuard.
46
What is StackGuard?
Inserts a canary value before the return address to detect overruns.
47
Who developed StackGuard?
Crispin Cowan and others in 1998.
48
What is a canary in StackGuard?
A guard value that detects if a buffer overflow alters the return address.
49
What is a limitation of StackGuard?
Doesn’t protect against overflows overwriting other values.
50
What is PointGuard?
An extension of StackGuard to protect additional data like function pointers.
51
What data does PointGuard protect?
Function pointers and longjump buffers automatically.
52
What is a challenge with PointGuard?
Requires programmer intervention to protect other variables.
53
Why might PointGuard miss vulnerabilities?
Programmers may overlook data needing protection.
54
What is the benefit of /GS and StackGuard?
Prevents exploitation of simple stack-based overruns.
55
Where can more info on StackGuard be found?
Cowan’s 1999 paper on buffer overflows.
56
Why validate all function inputs?
Prevents buffer overruns from unchecked user data.
57
What is the SafeStr library?
Dynamically resizes strings to prevent buffer overruns.
58
Why is strlcpy criticized?
Encourages use of C strings, not part of GNU C library.
59
What OSes support strlcpy/strlcat?
OpenBSD, FreeBSD, Solaris, Mac OSX, QNX.
60
Why use std::string in C++?
Native, safe string handling avoids buffer overrun risks.