/*
 * Simple heap overflow exploitable program
 *
 * Compile:
 *	gcc -o heap_vuln heap_vuln.c -Wall 
 *
 * THIS PROGRAM IS FOR EDUCATIONAL PURPOSES *ONLY*
 * IT IS PROVIDED "AS IS" AND WITHOUT ANY WARRANTY
 * 
 * (c) 2004 Copyright by inode <inode@wayreth.eu.org>
 *
 */

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char ** argv)
{
	char * heap1;
        char * heap2;

	FILE * in;
	long l;

        heap1 = malloc(512);
        heap2 = malloc(512);

        printf("VULN: heap at: 0x%p\n", heap1);


	if( (in = fopen("x.heap","rb")) == NULL ) {
		printf("Can't read file\n");
		exit( 1 );
	}

	fseek(in, 0L, 2);
	
	l = ftell(in);

        fseek(in, 0L, 0);

	printf("VULN: Reading %lu bytes\n", l);

	fread( heap1, l, 1, in);

	fclose( in );
	
	free( heap1 );
	free( heap2 );

	heap1 = malloc(1024);

	printf("VULN: Hi, my name is pete!\n");
	
	free( heap1 );

	exit( 0);	

}

