skills/dsoftbus-security/SKILL.md
OpenHarmony软总线代码安全检视专家 - 全面检查C/C++代码的安全编码规范和日志规范。 涵盖40+条安全规则,包括指针安全、内存管理、锁管理、敏感信息保护等关键领域。 提供跨文件调用分析和控制流分析,生成详细的代码审查报告。 仅在用户输入包含"软总线安全卫士"时触发。 ⚠️ 重要:此技能为只读审查工具,不修改源文件。
npx skillsauth add openharmonyinsight/openharmony-skills dsoftbus_safety_guardInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
⚠️ 此技能仅在用户输入包含"软总线安全卫士"时才会被调用
触发示例:
软总线安全卫士 请审查这个文件:D:\code\example.c请使用软总线安全卫士检查这个目录软总线安全卫士 检视lnn_lane_dfx.c文件本技能是 OpenHarmony distributed soft bus (dsoftbus) 通信组件的专用代码审查工具,涵盖:
⚠️ 核心原则:本技能为只读代码审查工具,仅分析代码并生成报告,不修改任何源文件。
根据代码特征快速定位相关规则:
| 代码特征 | 相关规则 |
|---------|---------|
| 函数返回 SOFTBUS_ERR | 日志规范-1 |
| 指针位运算 (&, \|, ^, ~, <<, >>) | 指针安全-1, 整数运算-2 |
| *ptr 或 ptr-> 使用 | 指针安全-3, 临时变量-1 |
| arr[index] 访问 | 数组下标-1,2 |
| SoftBusMutexLock/SoftBusMutexUnlock | 锁管理-1,2,3 |
| SoftBusSocketCreate/SoftBusSocketClose | fd管理-1,2 |
| malloc/free, new/delete | 内存管理-1~11 |
| HILOG_INFO 打印敏感信息 | 敏感信息-1,2,3 |
-| 无符号数递减 (i--) | 循环变量-1 |
| memcpy_s, strcpy_s 等 | 安全函数-1,2 |
| 路径操作 (., ..) | 外部输入-1 |
| IPC 接口新增 | 权限校验-1 |
每个规则的详细解释、代码示例和修复方案请查看:
💡 快速定位: 点击每个规则后的链接可查看详细说明和代码示例
git status --porcelain <path>git status --porcelain按照40+条规则逐项检查,参考:
核心能力:分析函数调用链,追踪跨文件的数据流和资源传递
核心能力:分析代码执行路径,识别不可达代码和路径敏感问题
⚠️ 重要限制:仅生成修复建议代码到报告中,严禁直接修改源文件
对每个问题提供:
创建报告目录:d:/code-review-YYYYMMDD-HHMMSS/
报告文件:
code_review_report.md - 完整审查报告code_fixes.patch - 所有修复代码(Git patch格式)statistics.json - 统计数据💡 详细检查方法: 每种错误模式的详细检查方法、代码示例和修复方案,请查看 检查清单
| 错误模式 | 危险等级 | 快速检测 | 详见章节 |
|---------|---------|---------|---------|
| 空指针解引用 | 🔴 严重 | *ptr 或 ptr-> 前无NULL检查 | 指针安全-3 |
| 锁未释放 | 🔴 严重 | return前未调用Unlock | 锁管理-1 |
| 内存泄漏 | 🔴 严重 | malloc未配对free | 内存管理-2 |
| 敏感信息泄露 | 🔴 严重 | 日志打印密钥/udid | 敏感信息-1 |
| 数组越界 | 🔴 严重 | arr[index] 未验证范围 | 数组下标-1 |
| 无符号死循环 | 🔴 严重 | uint32_t i-- | 循环变量-1 |
| 指针位运算 | 🟡 警告 | ptr & mask | 指针安全-1 |
| 整数溢出 | 🟡 警告 | size + offset 未检查 | 整数运算-1 |
| 返回SOFTBUS_ERR | 🟡 警告 | return SOFTBUS_ERR | 日志规范-1 |
| 未初始化变量 | 🟡 警告 | 声明未赋初值 | 临时变量-1 |
安全编码问题 > 日志规范问题
严重问题 > 警告问题 > 提示问题
⚠️ 严禁修改源代码:
references/security_rules_explained.md 了解每条规则的详细说明和代码示例d:/code-review-时间戳/ 目录生成报告YYYYMMDD-HHMMSS 格式的时间戳testing
--- name: ohos-req-value-decision description: Use after review meeting to record decision and route to next step. Triggers: 评审决策纪要, 评审结论回流, value decision, 评审接纳, 评审不接纳, 评审退回, 下次重新上会. Do NOT use for feature baseline (ohos-req-feature-baseline), review gate checks (ohos-req-review-gate), or IR generation (ohos-req-feature-to-ir). metadata: author: openharmony scope: common stage: requirements capability: value-decision version: 0.3.0 status: draft tags: - sdd - requirements
development
Use when converting an OpenHarmony requirement document, spec, or design proposal into an OpenHarmony review slide deck (需求评审 / 需求变更评审 / 设计评审 PPTX) — produces the fixed OpenHarmony-branded review-deck structure (OH logo on every page) with architecture/flow diagrams and field tables. Triggers on "需求评审PPT", "需求变更评审", "把需求文档转成评审PPT", "spec转评审PPT", "requirement/spec to review deck". NOT for arbitrary or generic slide decks unrelated to OpenHarmony requirement/design review.
testing
Use when performing the Phase 0 Step 0.5 Review Ready Gate on a 04-feature.md, especially when the user says "evaluate gate", "review readiness", "feature ready?", "should we generate IR", or when the ohos-req-intake-orchestration main session needs a structured Ready / Conditional Ready / Not Ready judgment instead of doing the check inline. Reads 01-04, runs seven fixed checks plus a conditional-items check, and returns a machine-readable JSON summary plus a human-readable table that the main session can route on. Do NOT use for feature baseline generation (ohos-req-feature-baseline), value decision recording (ohos-req-value-decision), or IR generation (ohos-req-feature-to-ir).
testing
--- name: ohos-req-requirement-intake description: Use when importing an OHOS requirement into Phase 0.1, especially for 01-requirement.md, requirement intake, background, user value, scenarios, scope, FR/NFR, affected modules, or priority. Triggers: 需求导入, 01-requirement, 需求基线, RR单号. Do NOT use for feasibility analysis (ohos-req-feasibility-analysis), architecture decision (ohos-req-arch-decision), or feature baseline (ohos-req-feature-baseline). metadata: author: openharmony scope: common