Read the man page for the function. On my system:
Quote:
char *gets(char *s);
...
gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with '\0'. No check for buffer overrun is performed (see BUGS below).
...
BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance how man characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.
|
gets() does not allocate a buffer for you. So you have to allocate memory for it yourself. No matter how much space you allocate, a string can be entered to exceed that space. By doing so, an unscrupulous individual can overwrite contents of memory by giving a longer-than-expected input string. If that input string is long enough, it can overwrite the program's instructions stored in memory, replacing them with code the user wants to execute. At the very least, the string could be used to alter data in memory on the system, and that might cause the program to behave unexpectedly.