Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我能';t解决此故障查找器警告(CWE-78、CWE-120)_C++_C_Security_Warnings_Flawfinder - Fatal编程技术网

C++ 我能';t解决此故障查找器警告(CWE-78、CWE-120)

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

我无法解决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
  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
}