The program is running and waiting for a name. Type it in the Program input box under the terminal, not at the GDB prompt.
Program input, and observing an out-of-bounds write
Level 8 of 13 · interactive GDB exercise · runs in your browser
Give input to a program under the debugger, and use raw memory to see what an out-of-bounds write actually modifies on this build.
name holds 8 bytes, but the code lets 32 in. Extra bytes spill onto whatever sits next to it.
Send AAAAAAAAB to the program, then look at is_admin.
You work in a real GDB session on the program below. A breakpoint on line 14 was set and the program was started. It is now running, waiting for input.
#include <stdio.h>
#include <string.h>
int main(void) {
int is_admin = 0;
char name[8];
printf("name: ");
fflush(stdout);
/* BUG: reads up to 32 bytes into an 8-byte array. */
if (fgets(name, 32, stdin) == NULL) {
return 1;
}
name[strcspn(name, "\n")] = '\0';
printf("hello, %s\n", name);
if (is_admin != 0) {
printf("admin access granted (is_admin = %d)\n", is_admin);
}
return 0;
}
main.c, compiled with gcc -g -O0 -std=c11 -Wall -fno-omit-frame-pointer -fno-stack-protector -no-pie -fno-pie for 32-bit x86 Linux.
print <expr>x/<n><fmt><size> <addr>runcontinueprint/x <expr>(Program input field)continue. A longer write also destroys saved registers further up the frame. Restart with run and send exactly 9 characters.