Trigger Conditions
⚠️ This skill is invoked only when user input contains "软总线安全卫士"
Trigger Examples:
软总线安全卫士 请审查这个文件:D:\code\example.c请使用软总线安全卫士检查这个目录软总线安全卫士 检视lnn_lane_dfx.c文件
Skill Overview
This skill is a dedicated code review tool for the OpenHarmony distributed soft bus (dsoftbus) communication component, covering:
- Logging Standards Check: 1 core rule
- Secure Coding Check: 40+ rules, covering 11 major categories
- General Code Quality Check: code complexity, readability, concurrency safety, etc.
- Cross-file Call Analysis: call chain tracing, resource passing, data flow analysis
- Control Flow Analysis: path-sensitive analysis, unreachable code detection
⚠️ Core Principle: This skill is aread-only code review tool, only analyzes code and generates reports,does not modify any source files。
Applicable Scenarios
- OpenHarmony dsoftbus component code
- C/C++ system-level communication code
- Code involving IPC, network communication, and multithreading
- Code requiring strict logging standards and secure coding
Quick Reference: Key Rule Index
Quickly locate relevant rules based on code characteristics:
| Code Characteristic | Related Rules |
|---|---|
| Function returns SOFTBUS_ERR | Logging Standards-1 |
Pointer bitwise operation (&, |, ^, ~, <<, >>) |
Pointer Safety-1, Integer Operations-2 |
*ptr or ptr-> used |
Pointer Safety-3, Temporary Variables-1 |
arr[index] access |
Array Subscript-1,2 |
SoftBusMutexLock/SoftBusMutexUnlock |
Lock Management-1,2,3 |
SoftBusSocketCreate/SoftBusSocketClose |
fd Management-1,2 |
malloc/free, new/delete |
Memory Management-1~11 |
HILOG_INFO print sensitive information |
Sensitive Information-1,2,3 |
| - | Unsigned number decrement (i--) |
memcpy_s, strcpy_s etc. |
Safe Functions-1,2 |
Path operations (., ..) |
External Input-1 |
| IPC interface added | Permission Check-1 |
📚 Detailed Rule Descriptions
For detailed explanations, code examples, and remediation solutions for each rule, see:
- Detailed Rule Explanations and Examples - Complete documentation of 40+ rules
- Problem description, risk level, problem example, remediation solution, and inspection points for each rule
- Includes complete code examples and best practices
- Includes a formatted print type matching table and a list of commonly used safe functions
🏷️ Rule Categories (Quick Index)
💡 Quick Locate: Click the link after each rule to view detailed explanations and code examples
1. Logging Standards (1 item)
- Returning SOFTBUS_ERR is prohibited → Detailed description
2. Pointer safety (4 items)
- Pointer bitwise operations are prohibited → Detailed description
- Check sizeof usage → Detailed description
- Null pointer dereference check → Detailed description
- Null check of IPC results → Detailed description
3. Temporary variables (3 items)
- Pointer variable initialization → Detailed description
- Resource descriptor initialization → Detailed description
- bool variable initialization → Detailed description
4. Array subscripts (2 items)
- Array out-of-bounds risk → Detailed description
- Validation of externally input subscripts → Detailed description
5. Lock management (3 items)
- Lock/Unlock used in pairs → Detailed description
- Lock variable consistency → Detailed description
- Release the lock on all return paths → Detailed description
6. fd management (2 items)
- SocketCreate/Close used in pairs → Detailed description
- fd correctly closed → Detailed description
7. Memory management (11 items)
- Validation of size validity before allocation → Detailed description
- SoftBusMalloc/SoftBusCalloc used in pairs with SoftBusFree → Detailed description
- new used in pairs with delete → Detailed description
- Null check after memory allocation → Detailed description
- Set global variables to null after release → Detailed description
- Set to null after release in loop body → Detailed description
- Specific resource management (regcomp/regfree, cJSON_Parse/Delete, etc.) → Detailed description
8. Sensitive information (3 items)
- Printing keys, paths, addresses, etc. is prohibited → Detailed description
- Clear stack keys after use → Detailed description
- Anonymize printing of sensitive identifiers → Detailed description
9. Integer operations (2 items)
- Overflow, wraparound, division-by-zero risks → Detailed description
- Bitwise operations on signed integers are prohibited → Detailed description
10. Loop variables (2 items)
- Unsigned integer infinite loop → Detailed description
- Validation of loops controlled by external data → Detailed description
11. Secure functions (2 items)
- Check return values of secure functions → Detailed description
- Buffer size consistency → Detailed description
12. Permission verification (1 item)
- Permission verification for newly added SDK IPC interfaces → Detailed description
13. External input validation (4 items)
- Path normalization → See details
- Validity of TLV parsing length → See details
- Check the actual size of the source buffer → See details
- Complete verification plan → See details
14. External Data Validity (3 items)
- Addition/subtraction based on external input / memory allocation validation → See details
- Default length validation → See details
- TLV format length validation → See details
15. Common Issues (5 items)
- Exception branch resource release → See details
- Macro definition resource leak → See details
- Function return value consistency → See details
- Formatted print type matching → See details
- Struct byte alignment → See details
Code Review Workflow
Step 1: Interactively select the review scope
Scenario A: User specifies a path
- Check whether there are modifications under this path:
git status --porcelain <path> - If there are modifications, provide options:
- Perform a full review of all code under this path
- Perform an incremental review of the modified code (N files in total)
- If there are no modifications, directly perform a full review
Scenario B: User does not specify a path
- Check whether the current repository has modifications:
git status --porcelain - Provide options:
- Review the code of the entire repository
- Specify a review path
- Review the locally modified code (N files in total)
- Execute according to the user's choice
Step 2: Code specification check
Check item by item according to the 40+ rules, refer to:
- Detailed rule documentation - Detailed description and code examples for each rule
- Use the Grep tool to search for violation patterns
- Analyze in context to avoid false positives
Step 3: Cross-file call analysis
Core capability: Analyze function call chains, and trace cross-file data flow and resource transfer
- Call graph construction
- Cross-file resource tracking (malloc/free separation)
- Cross-file data flow analysis
- Cross-file error handling
- Cross-file access to global variables
Step 4: Control flow analysis
Core capability: Analyze code execution paths, and identify unreachable code and path-sensitive issues
- Control flow graph construction
- Unreachable code detection
- Path-sensitive analysis
- Uninitialized variable analysis
- Resource release path analysis
Step 5: Generate repair suggestions
⚠️ Important limitation:Only generate repair suggestion code into the report; modifying source files directly is strictly prohibited
For each issue, provide:
- Complete function or code block repair example
- Comments explaining the reason for the modification
- Multiple repair solutions (if any)
Step 6: Generate a review report
Create a report directory:d:/code-review-YYYYMMDD-HHMMSS/
Report file:
code_review_report.md- Complete review reportcode_fixes.patch- All repair code (Git patch format)statistics.json- Statistical data
Common Error Quick Reference Table
💡 Detailed inspection method: For detailed inspection methods, code examples, and remediation plans for each error pattern, see Checklist
| Error Pattern | Severity Level | Quick Detection | See Section |
|---|---|---|---|
| Null Pointer Dereference | 🔴 Critical | *ptr or ptr-> no NULL check before |
Pointer Safety-3 |
| Lock Not Released | 🔴 Critical | Unlock not called before return | Lock Management-1 |
| Memory Leak | 🔴 Critical | malloc not paired with free | Memory Management-2 |
| Sensitive Information Leak | 🔴 Critical | Key/udid printed in logs | Sensitive Information-1 |
| Array Out of Bounds | 🔴 Critical | arr[index] range not verified |
Array Index-1 |
| Unsigned Infinite Loop | 🔴 Critical | uint32_t i-- |
Loop Variable-1 |
| Pointer Bitwise Operation | 🟡 Warning | ptr & mask |
Pointer Safety-1 |
| Integer Overflow | 🟡 Warning | size + offset not checked | Integer Operation-1 |
| Returns SOFTBUS_ERR | 🟡 Warning | return SOFTBUS_ERR | Logging Standards-1 |
| Uninitialized Variable | 🟡 Warning | Declared without initial value | Temporary Variable-1 |
Inspection Principles
Context Analysis
- When inspecting, look at the context to confirm whether protective measures already exist
- Avoid false positives (e.g., global variables may be initialized elsewhere)
Apply Flexibly
- In addition to the 40+ clearly defined rules, general code quality checks are also required
- Code complexity, readability, concurrency safety, performance issues, etc.
Key Focus Areas
- Code paths that handle external input
- Resource usage in macro definitions
- Problematic code in conditional compilation
- High-risk security issues (null pointers, memory leaks, sensitive information leaks)
Prioritization
安全编码问题 > 日志规范问题
严重问题 > 警告问题 > 提示问题
Core Restrictions
⚠️ Modifying source code is strictly prohibited:
- This skillonly reads and analyzes code
- Generate remediation suggestionsfor reporting only
- Never directly modify any source file
- Read-only operations: use only read-only tools such as Read, Grep, Glob
📖 Reference Documentation
Detailed rule descriptions
- Rule details and examples - Detailed explanations and code examples for the 40+ rules
- Problem description, risk level, problem example, remediation plan, and inspection points for each rule
- Includes complete code examples and best practices
- Includes a formatted print type matching table and a list of commonly used safe functions
Additional Resources
- Common Error Quick Reference - Quickly locate error patterns
- Usage Tips - How to effectively use this skill
Usage Tips
- Quickly locate issues: Use the "Quick Reference" table to find relevant rules based on code characteristics
- Learn rules in depth: Read
references/security_rules_explained.mdto understand detailed explanations and code examples for each rule - Categorized review: Check item by item by category according to "Rule Categories" to avoid omissions
- Prioritize serious issues: Refer to the "Common Errors Quick Reference Table" to prioritize fixing high-risk issues
- Use the workflow: Conduct the review systematically according to the "Code Review Workflow"
Report requirements
- Automatic report generation: After the review is completed, automatically generate the report in the
d:/code-review-时间戳/directory - Report directory format: Use
YYYYMMDD-HHMMSSformat timestamps - File encoding: Report files use UTF-8 encoding to ensure Chinese displays correctly
- Fix code is for reference only: All fix code appears only in code blocks in the report file and is not written to the source code directory