codechecker介绍

codechecker 是一款代码审计工具,可以扫描源码中可能存在的漏洞。该工具的主要特点有两个:

  • clang sa/clang tidy 的多文件扫描,使用 tu_collector 对多个文件做了翻译单元的聚合,然后调用 clang sa/clang tidy 进行扫描
  • 项目管理服务器和报告展示界面

工具仓库地址:https://github.com/Ericsson/codechecker

整体架构

img

目录:

编译命令记录

  • 记录编译器指令,如make, cmake

  • 将编译器指令转化成为JSON格式

编译命令处理

  • 参数过滤

  • C/C++标准检查

  • 编译目标检测

  • gcc/g++ 硬编码路径收集

交叉编译单元和静态分析的预处理

  • 交叉编译单元:针对每一个编译动作生成AST输出

  • 统计分析:收集不同的信息,返回值检查等,这些信息可以在静态分析步骤被重用

分析运行

  • Multiple analyzers run parallel using the collected information in the pre analysis step if available

  • processes one Buildaction

  • constructs the analysis command

  • runs the static analyzer analyzer

  • postprocesses analysis results if required

  • collect failure information in case the analysis failed(compilation error or crash)

报告存储和可视化服务器

数据库

  • Configuration database:

  • authentication/session information

  • production configuration (database connection information…)

  • Report database:

  • Store multiple analyzer run results.

  • Data can be used to generate analysis statistics

命令行客户端

  • Can be used for CI integration in a jenkins job

  • provide multiple output types

web浏览器

工具使用流

img

1.codechecker log运行给定的编译命令并且记录执行的编译步骤。这会生成一个JSON格式的输出文件(编译数据库)。

2.codechecker analyze使用前面得到的JSON数据执行项目分析,生成分析结果,结果使用plist格式表示。

3.此步骤可以进行多种不同的分析:

  • codechecker parse 展示分析结果

  • codechecker store 存储结果到指定服务器

  • codechecker cmd diff 比较两个分析结果的

从功能上分为两大部分:

  • 分析

  • 展示

从使用方式上分为两种:

  • 命令行

  • web UI

README.md中给出的示例:

  1. 执行分析
1
CodeChecker check -b "cd ~/your-project && make clean && make" -o ./results

check命令和analyze命令的区别是,check会将在标准输出里打印分析结果,analyze需要log命令输出的JSON文件作为输入。check相当于log命令+analyze命令。

img

服务器其他功能

  • 用户认证授权功能

  • 产品管理

  • 执行管理

  • 执行展示和比较

  • 漏洞路径展示

  • 产品漏洞统计

命令行与Web界面的区别

分析器调用:

  • 分析器只能够使用命令行命令invoke来启用

  • 分析在用户本地执行

存储分析报告到服务器:

使用store命令进行分析报告存储

报告索引和可视化:

Feature name Command-line Web GUI
Listing basic (file, check message, …) report summary ✓ ✓
Listing advanced (detection status, review, …) report summary ✗ ✓
Basic (file path, check name, …) filtering of reports ✓ ✓
Advanced (detection status, detection date, …) filtering ✗ ✓
Printing bug path for report Only for local output folder ✓
Visualisation of bug path in the code Only through exporting to HTML ✓
Listing reports in the same file Only through filters ✓
Listing all reports in a product ✗ ✓