Skip to content

Create new rule detect system() in c and cpp files#18

Merged
DMarinhoCodacy merged 11 commits into
mainfrom
create-new-rule-detect-system()-c
May 22, 2026
Merged

Create new rule detect system() in c and cpp files#18
DMarinhoCodacy merged 11 commits into
mainfrom
create-new-rule-detect-system()-c

Conversation

@DMarinhoCodacy
Copy link
Copy Markdown
Contributor

No description provided.

@DMarinhoCodacy DMarinhoCodacy changed the title Create new rule detect system() c Create new rule detect system() in c and cpp files May 22, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/codacy-rules.yaml
Comment on lines +642 to +643
# Explicitly ignore calls to your custom namespace
- pattern-not: osutility::system(...)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread docs/multiple-tests/codacy-rules/results.xml Outdated
Comment thread docs/multiple-tests/codacy-rules/src/codacy-c-avoid-std-system.cpp
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 22, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

@codacy-production codacy-production Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 osutility namespace. Furthermore, the PR currently lacks test coverage for C++ (std::system), global namespace (::system), and the exclusion logic for osutility.

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

Comment thread docs/codacy-rules.yaml
Comment thread docs/codacy-rules.yaml
Comment on lines +642 to +643
# Explicitly ignore calls to your custom namespace
- pattern-not: osutility::system(...)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ 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-not exclusion for osutility::system (lines 642-643) from the rule codacy.c.security.avoid-std-system in docs/codacy-rules.yaml.

Comment thread docs/codacy-rules.yaml Outdated
@DMarinhoCodacy DMarinhoCodacy merged commit 494f4a0 into main May 22, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants