/*
  Demonstration of a buffer overflow.  C let's you go past the end of 
  an array, and if you do you will be potentially overwriting or accessing
  memory from some other variables in your program.  

  In this program we use scanf without specifying a max # of characters to read.
 */

#include <stdio.h>


int main(int argc, char *argv[]) {

  char s1[10]; char s2[10]; char s3[10];
  sprintf(s1, "%*s",9, "");
  sprintf(s2, "%*s",9, "");
  sprintf(s3, "%*s",9, "");

  printf("s1 = |%9s|\n", s1);
  printf("s2 = |%9s|\n", s2);
  printf("s3 = |%9s|\n", s3);

  printf("Now type something to put into s2, and if you give"
	 "more than 9 characters we could see something interesting\n");
  scanf("%s", s2); // and this is why you should never scanf %s without a max # characters specified (e.g., %99s)

  printf("And now...\n");

  printf("s1 = |%9s|\n", s1);
  printf("s2 = |%9s|\n", s2);
  printf("s3 = |%9s|\n", s3);
  
  return 0;
}