author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 04 Oct 2014 15:55:05 +0100 | |
changeset 203 | c75a03ab8ac9 |
child 205 | 88416b7df38c |
permissions | -rw-r--r-- |
203
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
#include <string.h> |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
#include <stdio.h> |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
#include <stdlib.h> |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
/* |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
I used as environment the virtual machine provided here |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
http://www.cis.upenn.edu/~cis551/box.tar |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
This is Debian/Etch with Linux 2.6.18 with gcc 4.1.2 from 2008. |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
Some installation notes for this virtual machine under VMWare |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
are here |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
http://www.cis.upenn.edu/~cis551/project1.pdf |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
I run the virtial machine under MacOSX using the program |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
VirtualBox available for free from |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
https://www.virtualbox.org |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
The C-program I compiled the program with |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=2 |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
*/ |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
void foo (char *bar) |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
{ |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
long my_long = 10; // in hex: \xF2\x03\x00\x00 |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
char buffer[28]; |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
printf("my_long value = %lu\n", my_long); |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
strcpy(buffer, bar); |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
printf("my_long value = %lu\n", my_long); |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
} |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
|
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
int main (int argc, char **argv) |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
{ |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
foo("my string is too long !!!!! "); // all is normal |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
foo("my string is too long !!!!! \x00\x00\x07\xE4"); // overwrites my_long |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
return 0; |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
} |
c75a03ab8ac9
test
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |