首页 > 入门 C

入门 C

有两个c语言写的简单程序(不是我写的),我刚入门,但是在研究程序是不是可能受到安全威胁,请问这两个程序在做什么,还有是不是可能受到安全威胁啊?
谢谢

int main(int argc,char *argv[],char **envp)
{
	char buf[80];
	buf[0]='\0';
	strcpy(buf,argc[1]);
	printf("\n The output of your command is \n");
	system(buf);
	exit(0);
}

-----------------------------------

#include <stdio.h>
#include <string.h>
void f(char *str)
{
	char buffer[20];
	strcpy(buffer,str);
	/*search_by_name returns true if the name you enter matches the one in database*/
	if(search_by_name(buffer))
		print("%s is registered\n");
}
main()
{
	char name[20];
	printf("Please enter your name \n");
	gets(name);
	f(name);
	
}

很容易受到攻击。因为字符数组大小是20,而传入的字符串参数没有检查大小,会导致栈溢出。


问题很明显,主要是两种

1. 不检查缓冲区大小,strcpy和gets函数都是这样
2. 使用system函数,可以执行任意命令,也有风险

【热门文章】
【热门文章】