Protostar heap0
About
This level introduces heap overflows and how they can influence code flow.
This level is at /opt/protostar/bin/heap0
Source code
1#include <stdlib.h> 2#include <unistd.h> 3#include <string.h> 4#include <stdio.h> 5#include <sys/types.h> 6 7struct data { 8 char name[64]; 9}; 10 11struct fp { 12 int (*fp)(); 13}; 14 15void winner() 16{ 17 printf("level passed\n"); 18} 19 20void nowinner() 21{ 22 printf("level has not been passed\n"); 23} 24 25int main(int argc, char **argv) 26{ 27 struct data *d; 28 struct fp *f; 29 30 d = malloc(sizeof(struct data)); 31 f = malloc(sizeof(struct fp)); 32 f->fp = nowinner; 33 34 printf("data is at %p, fp is at %p\n", d, f); 35 36 strcpy(d->name, argv[1]); 37 38 f->fp(); 39 40} 41