File: execheap.c

package info (click to toggle)
paxtest 0.9.6-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 360 kB
  • ctags: 145
  • sloc: ansic: 962; makefile: 587; asm: 53; sh: 44
file content (37 lines) | stat: -rw-r--r-- 726 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* execheap.c - Tests wether code in the heap can be executed
 *
 * Copyright (c)2003 by Peter Busser <peter@adamantix.org>
 * This file has been released under the GNU Public Licence version 2 or later
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "body.h"

char *testname = "Executable heap                          ";

void doit( void )
{
	char *buf;
	fptr func;

	buf = malloc( 1 );
	if( buf == NULL ) {
		fprintf( stderr, "Out of memory\n" );
		exit( 1 );
	}

	/* Put a RETN instruction in the buffer */
	*buf = '\xc3';

	/* Convert the pointer to a function pointer */
	func = (fptr)buf;

	/* Call the code in the buffer */
	func();

	/* It worked when the function returns */
	itworked();
}