当前位置: 技术问答>linux和unix
ubuntu 使用gets函数编译警告不能运行
来源: 互联网 发布时间:2017-02-03
本文导语: 本帖最后由 kuaildg 于 2012-02-11 14:24:06 编辑 各位大侠: 帮忙看看下面代码,通过ubuntu下的gcc编译出现警告之后,就退出编译。不知错在哪里,请各位大侠帮忙指点一下,谢谢! #include int main() ...
帮忙看看下面代码,通过ubuntu下的gcc编译出现警告之后,就退出编译。不知错在哪里,请各位大侠帮忙指点一下,谢谢!
#include
int main()
{
char str[8];
gets(str);
puts(str);
return 0;
}
小弟文件名为gets.c 编译命令 gcc gets.c -o gets
|
警告而已,并没有说不能编译
你运行./gets
你运行./gets
|
那就别用gets了,用fgets
|
可能是怕越界造成危险
|
Linux下查man,说的很详细了,如下:
Reads characters from standard input until a newline is found. The characters up
to the newline are stored in BUF. The newline is discarded, and the buffer is ter‐
minated with a 0.
This is a _dangerous_ function, as it has no way of checking the amount of space
available in BUF. One of the attacks used by the Internet Worm of 1988 used this to
overrun a buffer allocated on the stack of the finger daemon and overwrite the
return address, causing the daemon to execute code downloaded into it over the con‐
nection.
Reads characters from standard input until a newline is found. The characters up
to the newline are stored in BUF. The newline is discarded, and the buffer is ter‐
minated with a 0.
This is a _dangerous_ function, as it has no way of checking the amount of space
available in BUF. One of the attacks used by the Internet Worm of 1988 used this to
overrun a buffer allocated on the stack of the finger daemon and overwrite the
return address, causing the daemon to execute code downloaded into it over the con‐
nection.
|
++ 用fgets