Create new rule detect system() in c and cpp files#18
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new security rule, codacy.c.security.avoid-std-system, designed to detect potentially dangerous system() calls in C and C++ code. The reviewer provided feedback regarding the rule's definition, suggesting the removal of project-specific namespace exclusions to improve maintainability. Additionally, improvements were suggested for the test suite, including renaming the test source file to .cpp to match its C++ content and ensuring the test results XML correctly references the full filename.
| # Explicitly ignore calls to your custom namespace | ||
| - pattern-not: osutility::system(...) |
There was a problem hiding this comment.
The hardcoded exclusion for osutility::system(...) appears to be specific to the provided test case. General security rules should avoid including project-specific or arbitrary namespace exclusions in their definition, as this reduces maintainability and portability. If exclusions are necessary, they should be handled through configuration or more generic patterns.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new security rule to detect system() calls in C/C++ to prevent command injection vulnerabilities. While the core logic is sound, the PR includes redundant 'not' patterns that are already naturally excluded by the primary matchers.
Documentation is currently lacking standard security references like CWE-78, which are necessary for providing developers with remediation context. Additionally, although a test file is included in the file list, the specific scenarios required to validate C++ support, global namespace resolution, and the osutility exclusion appear to be missing or unverified. Codacy analysis indicates the code is otherwise up to standards.
About this PR
- The PR description is empty. Please provide context for the new rule and justify the specific exclusion of the
osutilitynamespace. Furthermore, the PR currently lacks test coverage for C++ (std::system), global namespace (::system), and the exclusion logic forosutility.
Test suggestions
- Verify detection of a standard
system("...")call in a .c file - Verify detection of
std::system("...")call in a .cpp file - Verify detection of global namespace
::system("...")call - Verify that
osutility::system("...")does not trigger the rule
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify detection of a standard `system("...")` call in a .c file
2. Verify detection of `std::system("...")` call in a .cpp file
3. Verify detection of global namespace `::system("...")` call
4. Verify that `osutility::system("...")` does not trigger the rule
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
| # Explicitly ignore calls to your custom namespace | ||
| - pattern-not: osutility::system(...) |
There was a problem hiding this comment.
⚪ LOW RISK
Suggestion: The pattern-not: osutility::system(...) exclusion and its accompanying comment are redundant. The positive patterns defined in the pattern-either block do not match calls qualified with the osutility:: namespace. Removing this simplifies the rule.
Try running the following prompt in your coding agent:
Remove the redundant comment and
pattern-notexclusion forosutility::system(lines 642-643) from the rulecodacy.c.security.avoid-std-systemindocs/codacy-rules.yaml.
No description provided.