author | Christian Urban <urbanc@in.tum.de> |
Fri, 01 Jun 2018 15:46:34 +0100 | |
changeset 564 | 3391a4fc3533 |
parent 202 | 6740798264c1 |
permissions | -rw-r--r-- |
24 | 1 |
#include <string.h> |
2 |
#include <stdio.h> |
|
3 |
#include <stdlib.h> |
|
4 |
||
5 |
/* |
|
6 |
I used as environment the virtual machine provided here |
|
7 |
||
8 |
http://www.cis.upenn.edu/~cis551/box.tar |
|
9 |
||
10 |
This is Debian/Etch with Linux 2.6.18 with gcc 4.1.2 from 2008. |
|
11 |
||
12 |
Some installation notes for this virtual machine under VMWare |
|
13 |
are here |
|
14 |
||
15 |
http://www.cis.upenn.edu/~cis551/project1.pdf |
|
16 |
||
17 |
I run the virtial machine under MacOSX using the program |
|
18 |
VirtualBox available for free from |
|
19 |
||
20 |
https://www.virtualbox.org |
|
21 |
||
22 |
The C-program I compiled the program with |
|
23 |
||
24 |
gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=2 |
|
25 |
||
26 |
*/ |
|
27 |
||
28 |
||
29 |
void foo (char *bar) |
|
30 |
{ |
|
31 |
float my_float = 10.5; // in hex: \x41\x28\x00\x00 |
|
32 |
char buffer[28]; |
|
33 |
||
34 |
printf("my float value = %f\n", my_float); |
|
35 |
||
36 |
strcpy(buffer, bar); |
|
37 |
||
38 |
printf("my float value = %f\n", my_float); |
|
39 |
} |
|
40 |
||
41 |
int main (int argc, char **argv) |
|
42 |
{ |
|
111
677179c76e35
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
24
diff
changeset
|
43 |
foo("my string is too long !!!!! "); // all is normal |
677179c76e35
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
24
diff
changeset
|
44 |
foo("my string is too long !!!!! \x10\x10\xc0\x42"); // overwrites my_float |
24 | 45 |
return 0; |
46 |
} |
|
47 |