Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tcache_dup.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>

char buf[0x20];

int main(int argc,char **argv)
{
//this is tcache
Expand All @@ -18,15 +21,16 @@ int main(int argc,char **argv)
void *p,*q,*r,*d;
p = malloc(0x10);
q = malloc(0x10);
free(q);
free(p);
printf("now , we have a tcache which is already free\n");
printf("We can modify its next pointer!\n");
*(uint64_t *)p = (uint64_t)q;
printf("now p's next pointer = q\n");
printf("p's next = %p ,q = %p\n",*(uint64_t *)p,q);
*(uint64_t *)p = (uint64_t)buf;
printf("now p's next pointer = buf\n");
printf("p's next = %p ,buf = %p\n",*(uint64_t *)p,buf);
printf("so,We can malloc twice to get a pointer to q,sure you can change this to what you want!\n");
r = malloc(0x10);
d = malloc(0x10);
printf("OK!, we get we want!\n");
printf("OK!, we get we want, d = %p\n",d);

}