programs/C1.c
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 08 Oct 2013 05:53:21 +0100
changeset 112 0711775cb6b0
parent 25 599939aad971
permissions -rw-r--r--
added
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
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
void foo (char *bar)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  float my_float = 10.5;    // in hex: \x41\x28\x00\x00
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  char  buffer[28];        
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  printf("my float value = %f\n", my_float);
112
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 25
diff changeset
    12
  strcpy(buffer, bar);   
25
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  printf("my float value = %f\n", my_float);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
int main (int argc, char **argv)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  // only float overwritten
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  foo("my string is too long !!!!! \x10\x10\xc0\x42"); 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  // also calls can_never_run
112
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 25
diff changeset
    21
  foo("my string is too long !!!!! \x10\x10\xc0\x42\x90\x90\x90\x90\x55\x84\x04\x08"); 
25
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  return 0;
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
// its address in my setup is \x08048455
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
void can_never_run()
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
{ 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  printf("This can never be executed!\n");
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  exit(0);
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32