/********************************************************************/
/* Operating Systems Concepts (MSc Conv / JMC2) 2004/'05            */
/*                                                                  */
/* check_pin.c - Program used in Chapter 6b for showing buffer      */
/*               overrun attack.                                    */
/*                                                                  */
/* Olav Beckmann 2003-12-04                                         */
/********************************************************************/

#include <stdio.h>
#include <stdlib.h>

#define MAX_PIN 4

const int secret_pin[] = { 1, 2, 3, 4 };


int check_pin( const int position, const int value ) {
  int pin[MAX_PIN];

  pin[position-1] = value;

  return pin[position-1] == secret_pin[position-1];
}


int main( int argc, char *argv[] ) {
  printf( "Hello. Checking your pin now.\n" );

  if( ! check_pin( atoi(argv[1]), atoi(argv[2]) ) ) {
    printf( "\nYou have entered a wrong digit.\n\n" );
    exit( -1 );
  }

 Success:
  printf( "\nYou have got in. What do you want to do?\n\n" );

  printf( "\nSuccess = %d\n", (int) &&Success );

  return 0;
}

