programs/C1.c
author Christian Urban <urbanc@in.tum.de>
Tue, 09 Oct 2012 14:42:16 +0100
changeset 31 22e6c014086b
parent 25 599939aad971
child 112 0711775cb6b0
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#include <string.h>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
#include <stdio.h>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
#include <stdlib.h>
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
// for installation notes see C0.c
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
void foo (char *bar)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  float my_float = 10.5;    // in hex: \x41\x28\x00\x00
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  char  buffer[28];        
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  printf("my float value = %f\n", my_float);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  strcpy(buffer, bar);  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  printf("my float value = %f\n", my_float);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
int main (int argc, char **argv)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  // only float overwritten
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  foo("my string is too long !!!!! \x10\x10\xc0\x42"); 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  // also calls can_never_run
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  //foo("my string is too long !!!!! \x10\x10\xc0\x42\x90\x90\x90\x90\x55\x84\x04\x08"); 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  return 0;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
// its address in my setup is \x08048455
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
void can_never_run()
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
{ 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  printf("This can never be executed!\n");
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  exit(0);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35