Buffer Overflow and Security in C/C++ Programming

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/52

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

53 Terms

1
New cards

What is a major advantage of using C?

C is a small language that is close to the hardware, allowing for highly efficient code.

2
New cards

What is a major disadvantage of using C/C++?

Using C/C++ can be dangerous due to vulnerabilities like buffer overflows.

3
New cards

What happens if you write to an out-of-bounds index in an array in C?

It results in undefined behavior, which can lead to security vulnerabilities.

4
New cards

What is the primary security issue associated with C/C++?

Buffer overflow is the number one security issue in software.

5
New cards

What should be done to prevent buffer overflow vulnerabilities?

Check array bounds at runtime.

6
New cards

Why have C and C++ not adopted array boundary checks?

For efficiency reasons.

7
New cards

What types of code are particularly vulnerable to buffer overflows?

Code handling untrusted input, such as network input and user input. Embedded software and untrusted files

8
New cards

What function should never be used due to buffer overflow risks?

The gets() function.

9
New cards

What is a safer alternative to gets()?

fgets(buf, size, stdin).

10
New cards

What is the risk associated with the strcpy() function?

It assumes the destination buffer is large enough, which can lead to overflow.

11
New cards

What is a safer alternative to strcpy()?

Use strncpy(dest, src, size) instead.

12
New cards

What is the difference between strcat() and strncat()?

strcat() appends the entire second string, while strncat() appends a specified number of characters.

13
New cards

What can happen if you use the wrong size argument in strncat()?

It can lead to buffer overflow if the size exceeds the buffer's capacity.

14
New cards

What is a common mistake when using strncpy()?

Not ensuring the destination is null-terminated after copying.

15
New cards

What is an implicit casting bug?

It occurs when a signed integer is implicitly cast to an unsigned integer, leading to unexpected behavior.

16
New cards

What is a format string vulnerability?

It occurs when user-controlled input is passed to a format function, allowing arbitrary memory access.

17
New cards

How can format string vulnerabilities be prevented?

Avoid user-controlled format strings and validate/sanitize all user inputs. Use explicit format strings, limited permissions, and static code analysis

18
New cards

What is the risk of using printf with user-controlled input?

It can lead to security breaches and system compromise.

19
New cards

What is a potential consequence of a buffer overflow in server code?

It can crash the server or allow an attacker to execute arbitrary code.

20
New cards

What should be done if the length of user input is unknown?

Always validate and check the length before processing.

21
New cards

What can happen if a negative length is used in malloc()?

It can lead to over-allocation or failure, resulting in buffer overflow.

22
New cards

What is the maximum value for a signed short integer?

32767 (2^15 - 1).

23
New cards

What is the significance of the null terminator in C strings?

It indicates the end of the string and is crucial for proper string handling.

24
New cards

What is the output of printf if the input is improperly formatted?

It may lead to printing unintended memory addresses or cause crashes.

25
New cards

What is the purpose of validating user input?

To prevent vulnerabilities such as buffer overflows and format string attacks.

26
New cards

What is a common mistake when calculating buffer sizes?

Using the wrong size argument, which can lead to buffer overflow.

27
New cards

What should be done to user inputs before using them in format functions?

Validate and sanitize all user inputs.

28
New cards

What is a safer way to use user input in format strings?

Use explicit format strings, e.g., printf("%s", userInput).

29
New cards

What is one method to minimize the impact of successful attacks?

Ensure that the process running the code has limited permissions.

30
New cards

What tool can be used to detect potential format string vulnerabilities?

Static code analysis tools.

31
New cards

What is a fundamental solution for preventing buffer overflow attacks?

Array bounds checking.

32
New cards

What is the purpose of making memory segments non-executable?

To prevent attackers from executing malicious code injected into stack or heap.

33
New cards

What compiler option can be used to mark the stack segment as non-executable?

-z noexecstack.

34
New cards

What is a canary word in the context of StackGuard?

A canary word is placed before each return address in a stack frame to detect buffer overflows.

35
New cards

What does RAD stand for in buffer overflow prevention?

Return Address Defender.

36
New cards

What is the role of a type-safe language in preventing buffer overflows?

Type-safe languages automatically enforce array bounds checking.

37
New cards

What is a weakness of using type-safe languages?

Most existing software is not written in type-safe languages.

38
New cards

What is anomaly detection used for in cybersecurity?

To identify data patterns that deviate from the norm, signaling potential security threats.

39
New cards

What does ASLR stand for?

Address Space Layout Randomization.

40
New cards

What is the purpose of ASLR?

To randomize the memory locations of key process components to make it harder for attackers.

41
New cards

What is one weakness of code randomization?

Performance overhead and the assumption that most attacks are code injection attacks.

42
New cards

What is memory address obfuscation?

A technique that randomizes the base addresses of various memory regions to complicate attacks.

43
New cards

What can be introduced to create random-length gaps in memory?

Padding in stack frames and between malloc allocations.

44
New cards

What is a common weakness of static source code analysis?

It can produce false positives and false negatives.

45
New cards

What is the main purpose of using safe C library functions?

To prevent buffer overflows by checking buffer boundaries.

46
New cards

What is a potential issue with using strcpy and strcat?

They do not check the buffer boundaries of destination buffers.

47
New cards

What happens when a buffer overflow attack is launched?

The return address and possibly the canary word are overwritten.

48
New cards

What is the role of StackGuard in buffer overflow prevention?

To protect against stack smashing by verifying the integrity of canary words.

49
New cards

What is a weakness of the RAD approach?

It only protects return addresses.

50
New cards

What is the effect of making segments of memory non-executable?

It prevents the execution of malicious code in those segments.

51
New cards

What is the main challenge of rewriting legacy code in type-safe languages?

The scale and complexity involved in the existing software.

52
New cards

What is a common method to detect unusual activities in cybersecurity?

Anomaly detection.

53
New cards

What does the NX bit do?

It helps the OS manage execution permissions for memory segments.