Medium
A stack buffer overflow with -fstack-protector enabled
Compiled with the default stack-protector enabled (-fstack-protector-strong, the default on most modern distros), what happens when this program runs?
main.cpp
#include <cstdio>
#include <cstring>
void vulnerable(const char* input) {
char buf[16];
strcpy(buf, input); // no bounds check; input is 63 bytes
printf("buf = %s\n", buf);
}
int main() {
char big[64];
memset(big, 'A', sizeof(big) - 1);
big[63] = '\0';
vulnerable(big); // overflows the 16-byte buf by ~47 bytes
return 0;
}28 of 53 in Operating Systems