我有以下示例程序:execve(“/ bin/sh”,0,0);在管道
#include <stdio.h>
int
main(int argc, char ** argv){
char buf[100];
printf("Please enter your name: ");
fflush(stdout);
gets(buf);
printf("Hello \"%s\"\n", buf);
execve("/bin/sh", 0, 0);
}
我,当我运行没有它的作品,因为它应该任何管道,并返回一个sh
PROMT:
bash$ ./a.out
Please enter your name: warning: this program uses gets() which is unsafe.
testName
Hello "testName"
$ exit
bash$
但这不起作用在管道中,我想我知道这是为什么,但我无法找出解决方案。示例运行波纹管。
bash$ echo -e "testName\npwd" | ./a.out
Please enter your name: warning: this program uses gets() which is unsafe.
Hello "testName"
bash$
我估计这事做与gets
在/bin/sh
收到EOF和promtly没有一条错误信息退出这样的方式清空stdin
的事实。
但是我怎样才能解决这个问题(如果可能的话,不要修改程序,如果不能删除gets
),这样即使我通过管道提供输入,我也能得到一个提示?
P.S.我在一台FreeBSD(4.8)机器上运行这个程序DS
***从不使用`gets`。它总是**打开缓冲区溢出安全漏洞。 – ThiefMaster 2011-12-14 17:53:21
我知道;)...这是我大学安全实验室计算机上缓冲区溢出尝试的一部分。纯粹的学术。 = D – 2011-12-14 17:58:15