Cppcheck 静态代码分析器真的能检测到像 "Relative Path Traversal (CWE-23)" 或 "Buffer Under-read(CWE-127)" 这样不太常见的警告吗?

Can Cppcheck static code analyzer actually detect not very common warnings like "Relative Path Traversal (CWE-23)" or "Buffer Under-read(CWE-127)"?

我正在 Juliet Test Suite 进行研究,我正在对这些代码应用一些静态分析器以生成警告。在 运行ning cppcheck 之后,我发现它无法检测到 manifest.xml 文件(元数据)中提到的许多错误。是我未能正确 运行 这个软件还是 cppcheck 无法检测到这些警告/错误?你遇到过他们吗?

到目前为止,我一直在 Juliet 测试套件上使用 cppchecker。我将在其上使用 Clang、Veracode 和 Flawfinder,因为我第一次尝试失败了。

这是我使用的命令。

cppcheck --enable=all -q --xml -I testcasesupport/ testcases/ 2>out.xml

在给定的元数据 manifest.xml 文件中,一些示例错误是 -

<?xml version="1.0" encoding="utf-8"?>
<container>
   <testcase>
     <file path="CWE127_Buffer_Underread__CWE839_connect_socket_01.c">
       <flaw line="111" name="CWE-127: Buffer Under-read"/>
     </file>
   </testcase>
   <testcase>
     <file path="CWE114_Process_Control__w32_char_connect_socket_03.c">
       <flaw line="124" name="CWE-114: Process Control"/>
     </file>
   </testcase>
   .
   .
   .
</container>

但是我的 output.xml 由 cppchecker 生成的文件没有这些错误中的大部分。 output.xml 文件中的大多数错误属于 'CWE-398' 错误,这是一种样式错误。但 cppcheck 可以检测常见错误,如 'array-out-of-bound' 或类似错误。

是不是 cppcheck 没有涵盖 Juliet 测试套件的这些不常见错误?如果是,还有什么其他静态分析器可以正确检测到它们?

cppcheck 相当简单,远非完美。它可以检测 some 问题 some 的时间。但并非所有问题始终存在。这或多或少适用于任何工具。但是除了 cppcheck 之外,还可以试试 clang-tidy 和各种消毒剂(asan、tsan、ubsan 等)。

Clang-tidy is pretty good and free (see the list of checks).

Coverity是我用过的最好的,但是相当贵。

对于运行时检查,Address Sanitizer , Thread sanitizer and Undefined Behaviour Sanitizer都很棒。

当然,请始终从编译器中启用尽可能多的警告,并在启用和不启用优化的情况下进行构建以捕获不同的错误。

我是 Cppcheck 开发人员。

Am I failing to run this software properly or cppcheck just can't detect these warnings/ errors? Have you faced them before?

要了解 Cppcheck 可以检测到哪些 CWE,您可以使用此命令:

./cppcheck --errorlist

在输出中查找 "cwe"。

Is it that cppcheck doesn't cover these uncommon errors of Juliet Test Suite? If it is, what could be some other Static Analyzer that could detect them properly?

我不记得 Juliet 测试套件涵盖了哪些 CWE,但 Cppcheck 并未涵盖所有 CWE。而且我认为没有任何工具可以涵盖所有 CWE。

cppcheck is fairly simplistic and far from perfect.

我同意。我相信 KISS 原则。 Cppcheck 远非完美。

But try out clang-tidy and the various sanitizers (asan, tsan, ubsan etc) in addition to cppcheck.

我同意。最佳做法是使用多种工具。即使您使用最昂贵的工具(例如 NASA 使用各种昂贵的工具以及 Cppcheck,因为 Cppcheck 检测到一些未检测到的问题,反之亦然),这也是最佳实践。

I am working on Juliet Test Suite for my research

在我看来,Juliet 测试套件制作不精良。该代码很奇怪且不切实际。您的结论将仅具有学术意义。 运行 真实代码上的工具。

我建议你扫描一些重要的开源项目。 Cppcheck 可以在 Debian 中发现成千上万的错误(未定义的行为),并且该软件安装在数百万台计算机上。最新稳定版 linux 的状态不是很好。 :-(