什么vulnerabilty在此代码,请有人解释我这个代码C++ BOF漏洞请有人解释
#include <stdio.h>
#include <string.h>
int main(int arc, char* argv[])
{
char buff[50];
strcpy(buffer, argv[1]);
printf("You are string: %s", buff);
return 0;
}
什么vulnerabilty在此代码,请有人解释我这个代码C++ BOF漏洞请有人解释
#include <stdio.h>
#include <string.h>
int main(int arc, char* argv[])
{
char buff[50];
strcpy(buffer, argv[1]);
printf("You are string: %s", buff);
return 0;
}
argv[1]
可能不存在,或者它可能是超过50个字符=>问题。
解决方法:检查argc >=2
和strlen(argv[1])<50
否则,你的程序未定义的行为,
意味着它可以做一些奇怪和意外。
此外,恶意的人也许可以注入自己的代码
如何修补此 – mans 2014-10-27 08:21:06
的解决方案是已经在答案。你知道如何做一个条件? – deviantfan 2014-10-27 08:22:37
想象着你的参数超过49个字符长调用该程序。怎么了? – 2014-10-27 08:05:07
'的strcpy(缓冲液,的argv [1]);'也应该阅读'的strcpy(浅黄色,argv的[1]);' – Lionel 2014-10-27 09:21:01