Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1char name[8]; strcpy(name, "Alexandra123"); | Ainput = "A" * 200 + attacker_code | |
| 2strncpy(name, input, 7); | BA bigger buffer only delays the problem, because longer input can still overflow it. The program must always check input length before copying. | |
| 3An overflow can crash a program, because overwritten memory may hold data the program needs to keep running | Cgets() reads any amount of input with no size limit, so long input overflows the 4-character buffer. Use fgets(buf, 4, stdin) instead. | |
| 4An attacker can craft input that overflows a buffer and overwrites memory with their own instructions | DCopies at most 7 characters, so the input cannot spill past the end of the buffer | |
| 5char buf[4]; gets(buf); // no length check | ECopies 12 or more characters into a buffer that holds only 8, so the extra data overflows into nearby memory | |
| 6Fix: make the buffer bigger and skip checking input length | FSegmentation fault (core dumped) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
buffer overflow — When a program writes more data into a memory area (buffer) than it can hold, overwriting nearby memory. This can crash the program or let an attacker run their own code.char name[8];strcpy(name, input);strncpy(name, input, sizeof(name) - 1);if (strlen(input) > 7) return;buffer ← ARRAY OF 8 BYTES
FOR i ← 0 TO 7
buffer[i] ← data[i]