- 論壇徽章:
- 0
|
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int i = 1;
char buf[4];
strcpy(buf, "AAAA");
printf("%d\n", i);
return 0;
}
a) When compiled and executed on x86, why does this program usually not
output what the programmer intended?
strcpy拷貝結(jié)束符('\0')時 因為buf大小為4字節(jié),覆蓋了i的最低字節(jié)(之前是1) 變?yōu)?;
所以輸出結(jié)果是0
b) Name several ways in which the security problem that causes this
program not to output what the programmer intended can be prevented
WITHOUT changing the code.
但是這道題就不會了, 翻譯是不是這樣
找出幾種可以解決引起上面程序沒有按程序員意向輸出的安全隱患的預(yù)防方法,且不用改變源碼(就是上面那程序)
e文差不知道翻譯對不對,
求方法(因為我除了該代碼(比如說把buf改為buf[5]),就沒有別的辦法了) |
|