我有以下示例程序: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