-
-
Save akkartik/8a82115c8a356fc1aa0eb7917206ff22 to your computer and use it in GitHub Desktop.
Stride through the heap until segfault
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linux only. | |
// gcc x.c && ./a.out | |
// | |
// Example run on a 64-bit system: | |
// 0x56339fd78000 0x56339f74601a | |
// 0x56339fd78000 0x56339f74601b | |
// 0x56339fd78000 0x56339f74601c | |
// 0x56339fd78000 0x56339f74601d | |
// 0x56339fd78000 0x56339f74601e | |
// ... | |
// 0x56339fd78000 0x56339f746ffc | |
// 0x56339fd78000 0x56339f746ffd | |
// 0x56339fd78000 0x56339f746ffe | |
// 0x56339fd78000 0x56339f746fff | |
// 0x56339fd78000 0x56339f747000 | |
// zsh: segmentation fault ./a.out | |
#include<unistd.h> | |
#include<stdio.h> | |
char a = 0; | |
char end_of_data_segment = 0; | |
int main(void) { | |
int* program_break = sbrk(0); | |
char* curr = &end_of_data_segment; | |
while (1) { | |
printf("%p %p\n", program_break, curr); | |
fflush(stdout); | |
a = *curr; | |
++curr; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment