progs/test.c
changeset 203 c75a03ab8ac9
child 205 88416b7df38c
equal deleted inserted replaced
202:6740798264c1 203:c75a03ab8ac9
       
     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   long my_long = 10;    // in hex: \xF2\x03\x00\x00
       
    32   char  buffer[28];        
       
    33 
       
    34   printf("my_long value = %lu\n", my_long);
       
    35 
       
    36   strcpy(buffer, bar);  
       
    37  
       
    38   printf("my_long value = %lu\n", my_long);
       
    39 }
       
    40  
       
    41 int main (int argc, char **argv)
       
    42 {
       
    43   foo("my string is too long !!!!! ");                  // all is normal
       
    44   foo("my string is too long !!!!! \x00\x00\x07\xE4");  // overwrites my_long
       
    45   return 0;
       
    46 }
       
    47