cybersecurity · beginner · ~15 min · safe pentest lab
Model the canary integrity check.
Model the integrity check a function epilogue performs on its stack canary: the stored value must still equal the current one, or an overflow corrupted it.
Implement int canary_intact(unsigned long stored, unsigned long current) that returns 1 if the two values are equal, 0 otherwise.
stored: the canary value placed in the prologue.current: the canary value read back in the epilogue.Returns 1 if stored == current (canary intact), 0 otherwise (smashed).
canary_intact(0xdeadbeef, 0xdeadbeef) -> 1
canary_intact(0xdeadbeef, 0x41414141) -> 0 (overflow corrupted it)
The prologue's stored canary and the epilogue's current canary (unsigned long).
1 if stored == current; otherwise 0.
Equality check; a mismatch signals a stack overflow.
int canary_intact(unsigned long stored, unsigned long current) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.