-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap3.c
32 lines (25 loc) · 831 Bytes
/
heap3.c
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
/* demonstrates static pointer overflow in bss (uninitialized data) */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#define BUFSIZE 16
#define ADDRLEN 4 /* # of bytes in an address */
int main()
{
u_long diff;
static char *bufptr0;
static char buf[BUFSIZE];
static char *bufptr;
bufptr0 = bufptr = buf, diff = (u_long)&bufptr - (u_long)buf;
printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
&bufptr, bufptr, buf, diff, diff);
printf("bufptr0 (%p) = %p\n", &bufptr0, bufptr0);
memset(buf, 'A', (u_int)(abs(diff) + ADDRLEN));
printf("bufptr (%p) = %p, buf = %p, diff = 0x%x (%d) bytes\n",
&bufptr, bufptr, buf, diff, diff);
printf("bufptr0 (%p) = %p, buf2 = %p, diff = 0x%x (%d) bytes\n",
&bufptr0, bufptr0, buf, diff, diff);
return 0;
}