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, input); | ABounds checking: only copies the data if it fits inside the buffer | |
| 2if (len <= 8) { copy(input); } | BCopies input into an 8-byte buffer with no size check, so long input overflows into nearby memory | |
| 3Writing 20 characters into a space that holds only 10 overwrites nearby memory and can crash the program | CThe text is 11 characters but the buffer only holds 4, so the extra data overflows and overwrites nearby memory. | |
| 4Rejecting input that is longer than the buffer stops attackers overflowing it | DThe bounds check comes after the copy, so the overflow has already happened before the length is checked. | |
| 5char buf[4]; copy(buf, "HELLO WORLD"); | Ebuffer[10] = input_of_20_chars | |
| 6copy(buf, input); if (len <= 8) | Fif (len(input) > 10) { reject } |
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 than it can hold, spilling over and overwriting nearby memory. This can crash the program or let an attacker run their own code.char buffer[8];
strcpy(buffer, input);if (strlen(input) < sizeof(buffer)) {
strcpy(buffer, input);
}strncpy(buffer, input, sizeof(buffer) - 1);for (int i = 0; i < 8; i++) {
buffer[i] = input[i];
}char buffer[8];
strcpy(buffer, "AAAAAAAAAAAAAAAA");
// 16 bytes into 8 bytes = overflow