我有一个char数组,定义如下
char buffer[100];当我对点击率进行Flawfinder扫描时,我得到的是:
(buffer) char:
Statically-sized arrays can be improperly restricted, leading to potential
overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use
functions that limit length, or ensure that the size is larger than the
maximum possible length.我知道我必须在需要时进行检查,以确保我的代码是免费的,但是我们有任何方法来解决这个问题(以其他方式定义char数组)并使Flawfindr输出不受任何影响吗?
更新
下面是函数的完整代码,以防有帮助
std::string MyClass::randomGenerator(odb::nullable<int> maxLength) {
struct timeval tmnow;
struct tm *tm;
char buf[100];
gettimeofday(&tmnow, NULL);
tm = localtime(&tmnow.tv_sec);
strftime(buf, 100, "%m%d%H%M%S", tm);
string micro = std::to_string(((int)tmnow.tv_usec / 10000));
strlcat(buf, micro.c_str(), sizeof(buf));
std::stringstream stream;
stream << std::hex << stoll(buf);
std::string result(stream.str());
Utilities::find_and_replace(result, "0", "h");
Utilities::find_and_replace(result, "1", "k");
std::transform(result.begin(), result.end(),result.begin(), ::toupper);
if (maxLength) {
return result.substr(result.size() - maxLength.get(), result.size() - 1);
} else {
return result ;
}
}发布于 2020-07-19 03:51:46
Flawfinder确实是一个稍微美化了的grep -它不是一个真正的静态分析工具来进行数据流分析,所以我总是用健康的盐来获取它的输出!
真正应该编写这段代码的方法是使用C运行时函数编写真正的C++代码,而不是美化-C,这些函数绝对会导致内存损坏问题。
https://stackoverflow.com/questions/62969768
复制相似问题