programs/C0.c
changeset 111 677179c76e35
parent 24 525fe544bbe3
child 112 0711775cb6b0
equal deleted inserted replaced
110:fefd78525434 111:677179c76e35
     1 #include <string.h>
     1 #include <string.h>
     2 #include <stdio.h>
     2 #include <stdio.h>
     3 #include <stdlib.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 
     4 
    29 void foo (char *bar)
     5 void foo (char *bar)
    30 {
     6 {
    31   float my_float = 10.5;    // in hex: \x41\x28\x00\x00
     7   float my_float = 10.5;    // in hex: \x41\x28\x00\x00
    32   char  buffer[28];        
     8   char  buffer[28];        
    38   printf("my float value = %f\n", my_float);
    14   printf("my float value = %f\n", my_float);
    39 }
    15 }
    40  
    16  
    41 int main (int argc, char **argv)
    17 int main (int argc, char **argv)
    42 {
    18 {
    43   foo("my string is too long !!!!! ");                  \\ all is normal
    19   foo("my string is too long !!!!! ");                  // all is normal
    44   foo("my string is too long !!!!! \x10\x10\xc0\x42");  \\ overwrites my_float
    20   foo("my string is too long !!!!! \x10\x10\xc0\x42");  // overwrites my_float
    45   return 0;
    21   return 0;
    46 }
    22 }
    47 
    23