Skip to content

Instantly share code, notes, and snippets.

@olealgoritme
Created February 27, 2019 13:14
Show Gist options
  • Save olealgoritme/a7078f33cc5e4805efa61385ee44c071 to your computer and use it in GitHub Desktop.
Save olealgoritme/a7078f33cc5e4805efa61385ee44c071 to your computer and use it in GitHub Desktop.
buffer overflow (stack smashing)
#include <stdio.h>
#include <string.h>
char password[] = "password";
int get_password() {
int auth_ok = 0;
char buff[16];
printf("Enter password: ");
scanf("%s", buff);
if(strncmp(buff, password, sizeof(password)) == 0)
auth_ok = 1;
return auth_ok;
}
void success() {
printf("Success!\n");
}
int main(int argc, char** argv) {
int res = get_password();
if (res == 0) {
printf("Failure\n");
return 0;
}
success();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment