-
Notifications
You must be signed in to change notification settings - Fork 0
feat:coderabbit切换到 Assertive 断言模式,开启更多的安全扫描工具,测试Benchmark_C_CPP报出率 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||
| reviews: | ||||||||||||||
| max_files: 300 | ||||||||||||||
| branches: all | ||||||||||||||
| # 继续保持断言模式,不放过任何 corner case | ||||||||||||||
| profile: assertive | ||||||||||||||
|
|
||||||||||||||
| tools: | ||||||||||||||
| # 1. 核心静态分析:C/C++ 领域的经典老牌工具 | ||||||||||||||
| cppcheck: | ||||||||||||||
| enabled: true | ||||||||||||||
|
|
||||||||||||||
| # 2. LLVM 派系:作为 LLVM 开发者,这是你最熟悉的工具,能处理复杂的语法检查 | ||||||||||||||
| clang-tidy: | ||||||||||||||
| enabled: true | ||||||||||||||
|
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid tool name: According to the CodeRabbit configuration schema, the correct property name is 🔧 Proposed fix # 2. LLVM 派系:作为 LLVM 开发者,这是你最熟悉的工具,能处理复杂的语法检查
- clang-tidy:
+ clang:
enabled: true📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| # 3. 结构化搜索:利用 ast-grep 进行 AST 级别的模式匹配,适合查找特定的代码反模式 | ||||||||||||||
| ast-grep: | ||||||||||||||
| enabled: true | ||||||||||||||
|
|
||||||||||||||
| # 4. 安全深度防御:使用 Semgrep 进行语义化的漏洞扫描 | ||||||||||||||
| semgrep: | ||||||||||||||
| enabled: true | ||||||||||||||
|
|
||||||||||||||
| # 5. 供应链安全:扫描 C/C++ 依赖项中的已知漏洞 (CVEs) | ||||||||||||||
| osv-scanner: | ||||||||||||||
| enabled: true | ||||||||||||||
|
|
||||||||||||||
| # 6. 工程合规:自动检查 Shell 脚本(如构建脚本)中的错误 | ||||||||||||||
| shellcheck: | ||||||||||||||
| enabled: true | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .vscode/ | ||
| *build/ | ||
| Debug*/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Benchmark_C_CPP | ||
| 本仓库是 `Codesense` 产线 C/C++ 模块(`Saga` 和 `EasyVet`)的测试组件,可用于评估我方引擎以及相关竞品的分析能力。 | ||
|
|
||
| `Benchmark_C_CPP` 测试组件主要按照被分析程序特征、程序分析能力和应用场景等三方面进行组织,分别划分 `Features`、`Abilities` 和 `Applications` 等三个部分。这三个部分可以看作是相互独立的测试用例集,各有不同的侧重点。 | ||
|
|
||
| > 注意:本测试组件长期维护,根据项目的开发进展实时进行更新。未来还需要将各级标准(如 CWE)考虑进来。 | ||
|
|
||
| ## 被分析程序特征(Features) | ||
| 本部分按被分析程序的特征进行组织。程序的结构具有多样性,例如使用的数据类型多样、控制结构多样、语言特性多样等等,因此对静态分析的影响也不同,需要进一步分类以细化测试用例的设计。 | ||
|
|
||
| ### 数据类型(DataType) | ||
| + 数组(Arrays) | ||
| - 数据流存入数组的成员后取出 | ||
| - 数据流存入数组下标 `A`,取下标 `B` | ||
| - 数组中的成员 `A` 和 `B` 为别名 | ||
| - 大数组和二维数组中的别名 | ||
| + 浮点(Floats) | ||
| + 结构体(Structs) | ||
| - 数据流通过结构体成员进行传播 | ||
| - 结构体成员 `A` 和 `B` 存在别名关系,污染源传播到 `A`,`B` 传播到汇聚点 | ||
| - 结构体对象的指针 `A` 和 `B` 存在别名关系,通过 `A` 和 `B` 的同一个成员传播数据流 | ||
| - 多级嵌套的结构体 | ||
| + 全局变量和静态变量(Global) | ||
| - 全局变量和静态变量作为路径的条件 | ||
| + 类型转换(Cast) | ||
|
|
||
| ### 可终止性(Termination) | ||
| + 循环(Loop) | ||
| - 数据流路径上存在多个大循环(和条件无关) | ||
| - 数据流路径上存在多个大循环(和条件有关) | ||
| - 当循环满足某一个条件时传播数据流 | ||
| + 递归(Recursion) | ||
|
|
||
| ### 约束类型(Constraint) | ||
| + 按位运算约束(Bitwise) | ||
| + 线性运算(Linear) | ||
| + 非线性运算约束(NonLinear) | ||
|
|
||
| ### 数据流类型(Dataflow) | ||
| + 显式流(Explicit) | ||
| + 隐式流(Implicit) | ||
|
|
||
| ### 复杂语言特性(Language) | ||
| + 智能指针(SmartPtr) | ||
| + lambda 表达式(Lambda) | ||
| - lambda表达式引起的调用(路径条件等导致对象或指针取值不同) | ||
| + 函数指针(FuncPtr) | ||
| - lambda表达式、std::function、函数指针引起的调用(路径条件等导致对象或指针取值不同) | ||
| + 三目运算符(Ternary) | ||
| - 数据流经过三目运算符的分支 | ||
| + 引用(Reference) | ||
| - 利用C++引用来构造别名 | ||
| + 构造函数(Constructor) | ||
| - 隐式地调用了某些构造函数 | ||
| - 隐式地调用了某些析构函数 | ||
| + 指针运算(PointerArith) | ||
| + 异常处理机制(Exception):try-catch 等 | ||
| + 宏定义(Macro) | ||
| + 模板(Template) | ||
|
|
||
| ## 程序分析能力(Abilities) | ||
| 本部分按程序分析引擎中的分析能力进行组织。不同程序分析引擎提供的分析能力具有多样性,例如别名分析、各种敏感性分析等,按照引擎的分析能力对测试用例进行分类可以判断程序分析引擎具备哪些分析能力。 | ||
|
|
||
| ### 数据流分析(Dataflow) | ||
| + 别名分析(Aliasing) | ||
| + 常量传播(ConstantProp) | ||
|
|
||
| ### 过程间分析(InterProcedure) | ||
| + 标准(Regular) | ||
| - 污染源和汇聚点在同一函数 | ||
| - 污染源和汇聚点在不同函数 | ||
| + 调用图(CallGraph) | ||
| + 摘要(Summary) | ||
| + 参数(Param) | ||
| - 函数的不同参数之间为别名,在调用过程中进行隐式传播 | ||
| - 函数参数为指针,函数内修改了指针的值 | ||
|
|
||
| ### 敏感性分析(Sensitivity) | ||
| + 流敏感(Flow) | ||
| + 对象敏感(Object) | ||
| + 上下文敏感(Context) | ||
| - 数据流路径上经过同一函数的不同调用 | ||
| - 数据流的条件经过同一函数的不同调用 | ||
| + 域敏感(Field) | ||
| + 路径敏感(Path) | ||
| - 污染源和汇聚点在不同分支,数据流的路径条件满足/冲突 | ||
| - 在其中一个分支数据流断开,数据流的路径条件满足/冲突 | ||
|
|
||
| ### 环境建模(Env) | ||
| + 标准库(Std) | ||
| - 库函数使程序终止,阻止了数据流传播 | ||
| - 汇聚点在库函数内(`printf`、`strlen` 等) | ||
| - 污染源从库函数返回(`malloc`、`scanf` 等) | ||
| - 数据流经过库函数传播(`strcpy` 等) | ||
| - 库函数可能引起的路径条件(`strlen` 等) | ||
| - 数据流保存入 C++ STL 容器后返回 | ||
| - 数学函数的建模引起数据流传播或作为条件(`fabs`、`sin`、`cos`、`sqrt` 等) | ||
| + 第三方库(Third) | ||
| - qt 库 | ||
|
|
||
| ### 其他分析能力(Others) | ||
|
|
||
| ## 应用场景(Applications) | ||
| 本部分按应用场景进行组织。不同程序分析引擎在不同应用场景下的表现不同,使用不同应用场景下的真实程序可以反应程序分析引擎的真实水平,包括缺陷检测能力、性能等。本部分测试用例均为真实项目,可供测试部门进行使用,待未来进一步完善。 | ||
|
|
||
| ## 测试用例命名规范 | ||
| 测试用例的命名体现各级测试用例的分类名与对测试用例设计思路的描述。例如:`Features_DataType_Array_Cond.c` 表示 `Features-DataType` 目录(命名的前两个单词)下的测试用例,该测试用例的特点是使用了数组(命名的第三个单词),且数组操作出现在路径条件上(命名的第四个单词)。 | ||
|
|
||
| 测试用例中,主要存在正例和反例两类函数,这两个函数是进行静态分析的主体。正例函数命名为 `[filename]_good`,反例函数命名为 `[filename]_bad`。正例和反例的设计原则是根据对库博、蜚语等竞品和我方引擎的理解来设计,看怎么样尽可能暴露双方的缺陷。其中,正例的代码运行无缺陷,因此静态分析工具报告的问题都是误报;反例的设计遵循的原则是代码运行有缺陷,因此静态分析工具如果没有报出警告,则是漏报。 | ||
|
|
||
| 其它函数命名也遵循类似的原则,比如可以将 source 和 sink 单独提出,添加一个函数外壳,并命名为 `[filename]_source` 和 `[filename]_sink`。 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| //#include "benchmark.h" | ||
|
|
||
| void Abilities_Dataflow_Aliasing_2_update(int *ptr1, int *ptr2) { | ||
| *ptr1 = 5; | ||
| *ptr2 = 0; | ||
| } | ||
|
|
||
| int Abilities_Dataflow_Aliasing_2_main() { | ||
| int data = 10; | ||
| int *aliasPtr = &data; | ||
| Abilities_Dataflow_Aliasing_2_update(&data, aliasPtr); | ||
| int temp = 10/data; //Sink:CWE369除零错误 | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //指针别名分析 + 流敏感指针分析 | ||
| #include "benchmark.h" | ||
| void Abilities_Dataflow_Aliasing_Reference_1_good_Snk(int ***p, int ***q) { | ||
| if(**p){ | ||
| int c = ***q; //NO NPD | ||
| }else{ | ||
| int a = 1; | ||
| **p = &a; | ||
| int c = ***q; //NO NPD | ||
| } | ||
| } | ||
|
|
||
| void Abilities_Dataflow_Aliasing_Reference_1_bad_Snk(int **p, int **q) { | ||
| if(*p){ | ||
| int c = **q; | ||
| }else{ | ||
| int a = 1; | ||
| *p = &a; | ||
| int c = **q; // Sink: 空指针解引用 (Null Pointer Dereference, CWE476) x与y不属于指针别名 | ||
| } | ||
| } | ||
|
|
||
| int Abilities_Dataflow_Aliasing_Reference_1_good_main() { | ||
| int *a = NULL; | ||
| int **x = &a; | ||
| int **y = &a; | ||
| int ***w = &x; | ||
|
|
||
| Abilities_Dataflow_Aliasing_Reference_1_good_Snk(&y, w); | ||
| return 0; | ||
| } | ||
|
|
||
| int Abilities_Dataflow_Aliasing_Reference_1_bad_main() { | ||
| int *a = NULL; //Source: 指针a为null | ||
| int *x = a; | ||
| int *y = a; | ||
| int **w = &x; | ||
| Abilities_Dataflow_Aliasing_Reference_1_bad_Snk(&y, w); | ||
| return 0; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include "benchmark.h" | ||
| #include <stdio.h> | ||
|
|
||
| int *Abilities_Dataflow_ConstantProp_source() { | ||
| int *data = NULL; // Source: 空指针null | ||
| return data; | ||
| } | ||
|
|
||
| int Abilities_Dataflow_ConstantProp_sink(int *data) { | ||
| return *data; // Sink: 空指针解引用 (Null Pointer Dereference, CWE476) | ||
| } | ||
|
|
||
| int Abilities_Dataflow_ConstantProp_good(int *data, int value) { | ||
| int a = 10; | ||
|
|
||
| if(value > 0) | ||
| a += 5; | ||
| else | ||
| a -= 5; | ||
|
|
||
| if(a > 20) | ||
| Abilities_Dataflow_ConstantProp_sink(data); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int Abilities_Dataflow_ConstantProp_bad(int *data, int value) { | ||
| int a = 10; | ||
|
|
||
| if(value > 0) | ||
| a += 5; | ||
| else | ||
| a -= 5; | ||
|
|
||
| if(a > 5) | ||
| Abilities_Dataflow_ConstantProp_sink(data); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int Abilities_Dataflow_ConstantProp_good_main() { | ||
| int input; | ||
| scanf("%d", &input); | ||
| int* data = Abilities_Dataflow_ConstantProp_source(); | ||
| return Abilities_Dataflow_ConstantProp_good(data, input); | ||
| } | ||
|
|
||
| int Abilities_Dataflow_ConstantProp_bad_main() { | ||
| int input; | ||
| scanf("%d", &input); | ||
| int* data = Abilities_Dataflow_ConstantProp_source(); | ||
| return Abilities_Dataflow_ConstantProp_bad(data, input); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include <iostream> | ||
| #include <memory> | ||
|
|
||
| class Resource { | ||
| public: | ||
| void performTask() { | ||
| std::cout << "Performing a critical task." << std::endl; | ||
| } | ||
| }; | ||
|
|
||
| int Abilites_Env_Std_Move_bad(int param) { | ||
| auto resource = std::make_unique<Resource>(); | ||
| auto mayAccessResource = [resource = std::move(resource)](int x) -> bool { //source: resource移动到lambda中 | ||
| x = x * 3; | ||
| if(x > 0){ | ||
| return true; | ||
| }else{ | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| if (mayAccessResource(param)) { | ||
| resource->performTask(); // sink: Null pointer dereference; 因为resource已经被移动到lambda中 | ||
| } else { | ||
| std::cout << "Access denied or resource not available." << std::endl; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int Abilites_Env_Std_Move_good(int param) { | ||
| auto resource = std::shared_ptr<Resource>(); //共享资源,而不会遇到所有权被移动的问题。 | ||
| auto mayAccessResource = [resource = std::move(resource)](int x) -> bool { | ||
| x = x * 3; | ||
| if(x > 0){ | ||
| return true; | ||
| }else{ | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| if (mayAccessResource(param)) { | ||
| resource->performTask(); | ||
| } else { | ||
| std::cout << "Access denied or resource not available." << std::endl; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| class Widget { | ||
| public: | ||
| void doWork() const { | ||
| std::cout << "Widget is doing work." << std::endl; | ||
| } | ||
| }; | ||
|
|
||
| int Abilites_Env_Std_Vector_bad() { | ||
| std::vector<Widget*> widgets{new Widget(), nullptr, new Widget()}; // Souce: widgets contains nullptr | ||
|
|
||
| for (auto w : widgets) { | ||
| w->doWork(); // Sink: NPD | ||
| } | ||
|
|
||
| for(auto& w : widgets) { | ||
| delete w; | ||
| } | ||
| widgets.clear(); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int Abilites_Env_Std_Vector_good() { | ||
| std::vector<Widget*> widgets{new Widget(), nullptr, new Widget()}; // Souce: widgets contains nullptr | ||
|
|
||
| for (auto w : widgets) { | ||
| if(w) | ||
| w->doWork(); // Sink: NPD | ||
| } | ||
|
|
||
| for(auto& w : widgets) { | ||
| delete w; | ||
| } | ||
| widgets.clear(); | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid configuration property:
branchesis not recognized.The
branches: allsetting is not a valid property under thereviewssection according to the CodeRabbit schema. If you want to control which branches are reviewed, usereviews.auto_review.base_branchesinstead.🔧 Proposed fix
Remove this line, or if you need to specify base branches:
🤖 Prompt for AI Agents