Skip to content

Instantly share code, notes, and snippets.

@mk270
Created July 11, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk270/6d441ca4d609f48c1261 to your computer and use it in GitHub Desktop.
Save mk270/6d441ca4d609f48c1261 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int main(int argc, char *argv[], char *env[]) {
char *arena;
char hex[100];
char *target;
arena = malloc(1024);
strcpy(arena, "Hello world.\n");
sprintf(hex, "%lx\n", (intptr_t) arena);
/* in the real world example, the monstrosity in hex is passed to
a different function which has responsibility for sscanf()ing and
free()ing it */
sscanf(hex, "%lx", (intptr_t *) &target);
printf("%p\n%s\n", target, target);
free(target);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment