Skip to content

Instantly share code, notes, and snippets.

@mchow01
Created November 9, 2017 07:17
Show Gist options
  • Save mchow01/71307de6b885500ed4e998bab83d6594 to your computer and use it in GitHub Desktop.
Save mchow01/71307de6b885500ed4e998bab83d6594 to your computer and use it in GitHub Desktop.
From Jon Erickson's Hacking: The Art of Exploitation, 2nd Edition
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one"); /* put "one" into buffer_one */
strcpy(buffer_two, "two"); /* put "two" into buffer_two */
printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);
printf("\n[STRCPY] copying %d bytes into buffer_two\n\n", strlen(argv[1]));
strcpy(buffer_two, argv[1]); /* copy first argument into buffer_two */
printf("[AFTER] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[AFTER] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[AFTER] value is at %p and is %d (0x%08x)\n", &value, value, value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment