Skip to content

Instantly share code, notes, and snippets.

@michaelsproul
Created October 16, 2014 00:18
Show Gist options
  • Save michaelsproul/cfc0b60be5832ed79ff5 to your computer and use it in GitHub Desktop.
Save michaelsproul/cfc0b60be5832ed79ff5 to your computer and use it in GitHub Desktop.
scanf buffer overflow
// Enter a string of the form:
// # 1 "filenameiswaytoolong.cpp"
// You should get a segfault.
#include <stdio.h>
int main() {
int num;
char buffer[16];
char trailing[16];
int args_parsed = scanf("# %d \"%[^\"]\"", &num, buffer);
if (args_parsed == 2) {
printf("Filename: %s\n", buffer);
printf("Tailing: %s\n", trailing);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment