C++ 我能';t解决此故障查找器警告(CWE-78、CWE-120)
我无法解决Finder发现的这两个警告。你能给我一个正确代码的例子吗 最终结果:C++ 我能';t解决此故障查找器警告(CWE-78、CWE-120),c++,c,security,warnings,flawfinder,C++,C,Security,Warnings,Flawfinder,我无法解决Finder发现的这两个警告。你能给我一个正确代码的例子吗 最终结果: flawfinder_exercise_old_SAL_syntax.cpp:48: [4] (shell) system: This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality
flawfinder_exercise_old_SAL_syntax.cpp:48: [4] (shell) system:
This causes a new program to execute and is difficult to use safely
(CWE-78). try using a library call that implements the same functionality
if available.<br>
flawfinder_exercise_old_SAL_syntax.cpp:36: [2] (buffer) memcpy:
Does not check for buffer overflows when copying to destination (CWE-120).
Make sure destination can always hold the source data.*
这是第36行中的一个:
void copy_data(char *buf1,
char *buf2) {
memcpy(buf2,buf1,STR_SIZE);
buf2[STR_SIZE-1] = NULL; // null terminate, just in case
}
系统
功能的正确代码,它不使用它。该函数本质上是不安全的,因为它可能允许在您无法控制的情况下执行另一个程序。带有memcpy
的第二个变量也相当明确,您不需要检查任何潜在的溢出,因为buf2
的大小可能未知。但请记住,这些只是警告。嗨!谢谢你的回答!我知道你说的话,但对于学校来说,我必须解决这个警告,我不知道如何解决…:(对于memcpy
案例,尝试使用copy_数据(char*buf1,char*buf2,int size){memcpy(buf2,buf1,size);…}
和copy_数据(xx,yy,STR_size);
的copy_数据:函数不接受3个参数Argh…那么,现在是学习C语言基础知识的时候了。
void copy_data(char *buf1,
char *buf2) {
memcpy(buf2,buf1,STR_SIZE);
buf2[STR_SIZE-1] = NULL; // null terminate, just in case
}