-
Notifications
You must be signed in to change notification settings - Fork 0
testA #13
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: develop
Are you sure you want to change the base?
testA #13
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,25 @@ | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <limits.h> | ||
|
|
||
| #define MAX_BUFFER 10 | ||
|
|
||
| void buffer_overflow_vuln(char* user_input) { | ||
| char buffer[MAX_BUFFER]; | ||
| strcpy(buffer, user_input); | ||
| } | ||
|
|
||
|
|
||
| int integer_overflow_vuln(int count, int size) { | ||
| int total_bytes = count * size; | ||
|
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. 🟡 AI 代码审查发现问题 📋 问题概述
line 16 处将两个有符号 int 参数 count 和 size 直接相乘,未做任何溢出检查。C 标准规定有符号整数溢出是未定义行为。main 函数 line 23 以 INT_MAX 和 2 作为参数调用,INT_MAX * 2 必然超出 int 表示范围,触发有符号整数溢出 UB。 检查器: 📍 问题详情🟡 问题 1 | 严重程度:
|
||
| return total_bytes; | ||
| } | ||
|
|
||
|
|
||
| int main(int argc, char* argv[]) { | ||
| buffer_overflow_vuln(argv[1]); | ||
|
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. 🟡 AI 代码审查发现问题 📋 问题概述
line 22 处直接使用 argv[1] 作为参数调用 buffer_overflow_vuln,未检查 argc 是否 >= 2。当程序不带命令行参数运行时,argv[1] 为 NULL 指针,传入 buffer_overflow_vuln 后在 line 11 的 strcpy 中对 NULL 解引用,导致未定义行为(通常崩溃)。 检查器: 📍 问题详情🟡 问题 1 | 严重程度:
|
||
| int result = integer_overflow_vuln(INT_MAX, 2); | ||
| 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.
🔴 AI 代码审查发现问题
📋 问题概述
line 10 处声明了 10 字节的栈缓冲区 buffer[MAX_BUFFER](MAX_BUFFER=10),line 11 处使用 strcpy 将外部输入 user_input 无界复制到该缓冲区。strcpy 不会检查源字符串长度,当 user_input 长度超过 9 字节时发生栈缓冲区溢出。main 函数 line 22 直接将命令行参数 argv[1] 传入,攻击者可通过超长命令行参数触发溢出。
检查器:
clang-analyzer-security.insecureAPI.strcpy;报告器:clang-tidy📍 问题详情
🔴 问题 1 | 严重程度:
HIGH| 行号:11💬 详细说明:
📝 问题代码:
💡 修复建议:
✅ 修复示例:
🔗 参考链接
无