Mình chép 1 đoạn wikipedia nói về gets().
--------------------- Nguồn : http://en.wikipedia.org/wiki/Gets --------------------
gets is a function in the C standard library, declared in the header file stdio.h, that reads a line from the standard input and stores it in a buffer provided by the caller. It might be implemented as follows (using getchar):
Code:
char *gets(char *s)
{
int i, k = getchar();
/* Return NULL if no input is available */
if (k == EOF) return NULL;
/* Read and store characters until reaching a newline or end-of-file */
for (i = 0; k != EOF && k != '\n'; ++i) {
s[i] = k;
k = getchar();
/* If a read error occurs, the resulting buffer is not usable. */
if (k == EOF && !feof(stdin)) return NULL;
}
/* Null-terminate and return the buffer on success.
The newline is not stored in the buffer. */
s[i] = '\0';
return s;
}
As indicated by the code above, gets does not perform bounds checking on the input, and therefore is a potential source of buffer overflow exploits in programs that use it. Most gets man pages contain the warning "Never use gets"[1] precisely because of this design flaw.
While the use of gets is not officially deprecated by any C standard, its use is discouraged; it is left in the C89 and C99 standards for backward compatibility. Some development tools, such as lint, will emit warnings when code using gets is linked. The fgets(..., stdin) function is a frequently suggested substitute.
--------------------- Nguồn : http://en.wikipedia.org/wiki/Gets --------------------
Như vậy, vấn đề lại nằm ở chỗ "cây kiếm không chuôi" gets() này đã được thiết kế và giữ bản quyền thiết kế bởi một nhà tạo mẫu tồi: chuẩn ngôn ngữ C. Nên thợ rèn chỉ có 2 cách để chọn lựa: rèn theo đúng thiết kế, và kết quả là được 1 cây kiếm không chuôi; hoặc tự tiện cải biên thiết kế, rèn ra loại vũ khí khác, ví dụ, một cây dao găm. Cây dao găm này có thể có chuôi, đúng. Nhưng nó không phải là gets().
Thợ rèn nào cũng chỉ có 2 cách đó. Intel, Microsoft, GNU,... đều phải làm thế. Borland cũng không phải là ngoại lệ.