#include <stdio.h>//#define sz1 "Hello" Int main (int argc, char *argv[ ]) { //char sz1[8] = "Hello"; //const char *sz1 = "Hello"; char sz1[8]; char sz2[ 8]; memset (sz1,0x00,sizeof (SZ1)); strcpy (sz1, "Hello"); printf ("sz1=[%s]\n", sz1); while (1) { memset (sz2,0x00,sizeof (SZ2)); printf ("please input passwd:\n"); / /gets (SZ2); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%s", SZ2); //fgets (Sz2,sizeof (SZ2), stdin); printf ("--- Sz1=[%s]\n ", sz1); &nBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;PRINTF ("---sz2=[%s]\n", sz2); if (0 == strcmp (SZ1,SZ2)) { printf ("----hello world-----\ n"); break; } else { printf ("----ERROR----\ n"); continue; } } return 0;}
-----------------Test Results---------------
Sz1=[hello]
Please input passwd:
12345678ayang
---Sz1=[ayang]
---Sz2=[12345678ayang]
----ERROR----
Please input passwd:
Hello
---Sz1=[ayang]
---Sz2=[hello]
----ERROR----
Please input passwd:
Ayang
---Sz1=[ayang]
---Sz2=[ayang]
----Hello World-----
Windows buffer Overflow Vulnerability-unsafe function