/* 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. */ #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("setting s2 = 15 0s\n"); sprintf(s2, "%0*d", 15, 0); printf("s1 = |%9s|\n", s1); printf("s2 = |%9s|\n", s2); printf("s3 = |%9s|\n", s3); return 0; }