Skip to content
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

Add static analysis rules for NULL pointer dereference detection #132

Merged
merged 10 commits into from
Jan 20, 2025

Conversation

ESS-ENN
Copy link
Collaborator

@ESS-ENN ESS-ENN commented Jan 20, 2025

Summary by CodeRabbit

  • New Features

    • Added new security rules for detecting NULL pointer dereference issues in C and C++ code
    • Introduced test cases and snapshots for validating NULL library function handling
  • Tests

    • Added comprehensive test configurations for null-library-function-c and null-library-function-cpp
    • Created snapshot files to validate code patterns and function usage
  • Documentation

    • Included references to Common Weakness Enumeration (CWE-476) for NULL Pointer Dereference

Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

This pull request introduces new static analysis rules for detecting NULL pointer dereference vulnerabilities in C and C++ programming languages. Two new rule files (null-library-function-c.yml and null-library-function-cpp.yml) have been added to enhance code safety by identifying potential runtime errors. Corresponding test cases and snapshot files were also created to validate the rule implementations, covering scenarios involving file operations, environment variable handling, and function return value checks.

Changes

File Change Summary
rules/c/security/null-library-function-c.yml New rule for detecting NULL pointer dereferences in C
rules/cpp/null-library-function-cpp.yml New rule for detecting NULL pointer dereferences in C++
tests/c/null-library-function-c-test.yml Added test cases for C null library function rule
tests/cpp/null-library-function-cpp-test.yml Added test cases for C++ null library function rule
tests/__snapshots__/*-snapshot.yml Added multiple snapshot files for testing various scenarios

Sequence Diagram

sequenceDiagram
    participant Code
    participant Rule
    participant AST
    participant Analyzer
    
    Code->>AST: Parse source code
    AST->>Rule: Apply null dereference checks
    Rule->>Analyzer: Identify potential vulnerabilities
    Analyzer-->>Code: Report warnings for unsafe patterns
Loading

Possibly related PRs

Suggested reviewers

  • ganeshpatro321

Poem

🐰 Null Pointer's Peril

In code where pointers dance and sway,
A rabbit warns of dangers today,
Check before you leap and dereference wild,
Lest runtime chaos be compiled!
Safety first, my coder's friend! 🚦


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title @coderabbitai Add static analysis rules for NULL pointer dereference detection Jan 20, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🧹 Nitpick comments (4)
rules/c/security/null-library-function-c.yml (1)

21-23: Consider enabling commented patterns.

The commented patterns look valid and could enhance detection capabilities.

Consider enabling these patterns if they've been tested:

-    #  any:
-    #    - pattern: $SOURCE($$$)[$$$]
-    #    - pattern: ($SOURCE($$$))[$$$]
+      any:
+        - pattern: $SOURCE($$$)[$$$]
+        - pattern: ($SOURCE($$$))[$$$]
rules/cpp/null-library-function-cpp.yml (3)

1-11: Consider adding C++-specific references.

While the rule is well-documented, consider adding C++-specific references and best practices.

Add references to C++ core guidelines, such as:

  • C++ Core Guidelines: ES.65: Don't dereference an invalid pointer
  • C++ Core Guidelines: I.12: Declare a pointer that must not be null as not_null

33-33: Enhance function patterns for C++ standard library.

The regex patterns could be expanded to include more C++ standard library functions.

Consider adding patterns for:

  • Smart pointer functions (make_unique, make_shared)
  • String operations (string::c_str, string::data)
  • Container operations (vector::data)
  • File system operations (filesystem::path::c_str)

Also applies to: 62-62, 94-94, 114-114, 173-173, 196-196, 230-230, 244-244


13-262: Deduplicate rules between C and C++.

The C and C++ rules are identical, leading to maintenance overhead.

Consider:

  1. Creating a base rule with common patterns
  2. Extending it with language-specific patterns
  3. Using YAML anchors and aliases to reduce duplication
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 25-25: wrong indentation: expected 5 but found 7

(indentation)


[warning] 26-26: wrong indentation: expected 10 but found 12

(indentation)


[warning] 29-29: wrong indentation: expected 12 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 17 but found 18

(indentation)


[warning] 35-35: wrong indentation: expected 17 but found 18

(indentation)


[warning] 38-38: wrong indentation: expected 10 but found 11

(indentation)


[warning] 40-40: wrong indentation: expected 11 but found 13

(indentation)


[error] 42-42: trailing spaces

(trailing-spaces)


[warning] 45-45: wrong indentation: expected 5 but found 7

(indentation)


[warning] 46-46: wrong indentation: expected 10 but found 11

(indentation)


[warning] 51-51: wrong indentation: expected 10 but found 11

(indentation)


[warning] 54-54: wrong indentation: expected 12 but found 13

(indentation)


[error] 54-54: trailing spaces

(trailing-spaces)


[warning] 58-58: wrong indentation: expected 13 but found 15

(indentation)


[warning] 59-59: wrong indentation: expected 18 but found 19

(indentation)


[warning] 64-64: wrong indentation: expected 18 but found 19

(indentation)


[error] 66-66: trailing spaces

(trailing-spaces)


[error] 67-67: trailing spaces

(trailing-spaces)


[warning] 69-69: wrong indentation: expected 5 but found 7

(indentation)


[warning] 70-70: wrong indentation: expected 10 but found 11

(indentation)


[warning] 75-75: wrong indentation: expected 10 but found 11

(indentation)


[warning] 78-78: wrong indentation: expected 12 but found 13

(indentation)


[warning] 82-82: wrong indentation: expected 13 but found 15

(indentation)


[warning] 83-83: wrong indentation: expected 18 but found 19

(indentation)


[warning] 87-87: wrong indentation: expected 18 but found 19

(indentation)


[warning] 90-90: wrong indentation: expected 19 but found 21

(indentation)


[warning] 91-91: wrong indentation: expected 24 but found 25

(indentation)


[error] 95-95: trailing spaces

(trailing-spaces)


[warning] 98-98: wrong indentation: expected 5 but found 7

(indentation)


[warning] 103-103: wrong indentation: expected 10 but found 11

(indentation)


[warning] 106-106: wrong indentation: expected 12 but found 13

(indentation)


[warning] 110-110: wrong indentation: expected 13 but found 15

(indentation)


[warning] 111-111: wrong indentation: expected 18 but found 19

(indentation)


[warning] 116-116: wrong indentation: expected 18 but found 19

(indentation)


[warning] 119-119: wrong indentation: expected 10 but found 11

(indentation)


[warning] 120-120: wrong indentation: expected 12 but found 13

(indentation)


[warning] 123-123: wrong indentation: expected 14 but found 16

(indentation)


[warning] 127-127: wrong indentation: expected 10 but found 11

(indentation)


[warning] 128-128: wrong indentation: expected 12 but found 13

(indentation)


[warning] 131-131: wrong indentation: expected 13 but found 15

(indentation)


[warning] 132-132: wrong indentation: expected 18 but found 19

(indentation)


[warning] 136-136: wrong indentation: expected 18 but found 19

(indentation)


[warning] 139-139: wrong indentation: expected 20 but found 21

(indentation)


[warning] 142-142: wrong indentation: expected 22 but found 23

(indentation)


[warning] 148-148: wrong indentation: expected 5 but found 7

(indentation)


[warning] 149-149: wrong indentation: expected 10 but found 11

(indentation)


[warning] 154-154: wrong indentation: expected 10 but found 11

(indentation)


[warning] 157-157: wrong indentation: expected 12 but found 13

(indentation)


[error] 157-157: trailing spaces

(trailing-spaces)


[warning] 161-161: wrong indentation: expected 13 but found 15

(indentation)


[warning] 162-162: wrong indentation: expected 18 but found 19

(indentation)


[warning] 166-166: wrong indentation: expected 18 but found 19

(indentation)


[warning] 169-169: wrong indentation: expected 19 but found 21

(indentation)


[warning] 170-170: wrong indentation: expected 24 but found 25

(indentation)


[error] 173-173: trailing spaces

(trailing-spaces)


[error] 174-174: trailing spaces

(trailing-spaces)


[warning] 180-180: wrong indentation: expected 5 but found 7

(indentation)


[warning] 181-181: wrong indentation: expected 10 but found 11

(indentation)


[warning] 186-186: wrong indentation: expected 10 but found 11

(indentation)


[warning] 189-189: wrong indentation: expected 12 but found 13

(indentation)


[warning] 192-192: wrong indentation: expected 13 but found 15

(indentation)


[warning] 193-193: wrong indentation: expected 18 but found 19

(indentation)


[warning] 198-198: wrong indentation: expected 18 but found 19

(indentation)


[error] 200-200: trailing spaces

(trailing-spaces)


[warning] 203-203: wrong indentation: expected 5 but found 7

(indentation)


[error] 203-203: trailing spaces

(trailing-spaces)


[error] 204-204: trailing spaces

(trailing-spaces)


[warning] 206-206: wrong indentation: expected 5 but found 7

(indentation)


[warning] 207-207: wrong indentation: expected 10 but found 11

(indentation)


[warning] 212-212: wrong indentation: expected 10 but found 11

(indentation)


[warning] 215-215: wrong indentation: expected 12 but found 13

(indentation)


[error] 217-217: trailing spaces

(trailing-spaces)


[warning] 219-219: wrong indentation: expected 13 but found 15

(indentation)


[warning] 220-220: wrong indentation: expected 18 but found 19

(indentation)


[warning] 223-223: wrong indentation: expected 18 but found 19

(indentation)


[warning] 226-226: wrong indentation: expected 19 but found 21

(indentation)


[warning] 227-227: wrong indentation: expected 24 but found 25

(indentation)


[warning] 232-232: wrong indentation: expected 24 but found 25

(indentation)


[error] 234-234: trailing spaces

(trailing-spaces)


[warning] 237-237: wrong indentation: expected 6 but found 7

(indentation)


[warning] 241-241: wrong indentation: expected 10 but found 11

(indentation)


[error] 244-244: trailing spaces

(trailing-spaces)


[warning] 246-246: wrong indentation: expected 10 but found 11

(indentation)


[warning] 249-249: wrong indentation: expected 10 but found 11

(indentation)


[warning] 250-250: wrong indentation: expected 12 but found 13

(indentation)


[warning] 252-252: wrong indentation: expected 13 but found 15

(indentation)


[warning] 255-255: wrong indentation: expected 10 but found 11

(indentation)


[warning] 256-256: wrong indentation: expected 12 but found 13

(indentation)


[warning] 258-258: wrong indentation: expected 13 but found 15

(indentation)


[warning] 260-260: wrong indentation: expected 10 but found 11

(indentation)


[error] 262-262: no new line character at the end of file

(new-line-at-end-of-file)


[error] 262-262: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56e9aa5 and 87cebf1.

📒 Files selected for processing (8)
  • rules/c/security/null-library-function-c.yml (1 hunks)
  • rules/cpp/null-library-function-cpp.yml (1 hunks)
  • tests/__snapshots__/null-library-function-c-snapshot.yml (1 hunks)
  • tests/__snapshots__/null-library-function-cpp-snapshot.yml (1 hunks)
  • tests/__snapshots__/return-c-str-cpp-snapshot.yml (1 hunks)
  • tests/__snapshots__/sizeof-this-c-snapshot.yml (1 hunks)
  • tests/c/null-library-function-c-test.yml (1 hunks)
  • tests/cpp/null-library-function-cpp-test.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
tests/c/null-library-function-c-test.yml

[error] 17-17: trailing spaces

(trailing-spaces)


[error] 21-21: trailing spaces

(trailing-spaces)


[error] 29-29: no new line character at the end of file

(new-line-at-end-of-file)

rules/cpp/null-library-function-cpp.yml

[warning] 25-25: wrong indentation: expected 5 but found 7

(indentation)


[warning] 26-26: wrong indentation: expected 10 but found 12

(indentation)


[warning] 29-29: wrong indentation: expected 12 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 17 but found 18

(indentation)


[warning] 35-35: wrong indentation: expected 17 but found 18

(indentation)


[warning] 38-38: wrong indentation: expected 10 but found 11

(indentation)


[warning] 40-40: wrong indentation: expected 11 but found 13

(indentation)


[error] 42-42: trailing spaces

(trailing-spaces)


[warning] 45-45: wrong indentation: expected 5 but found 7

(indentation)


[warning] 46-46: wrong indentation: expected 10 but found 11

(indentation)


[warning] 51-51: wrong indentation: expected 10 but found 11

(indentation)


[warning] 54-54: wrong indentation: expected 12 but found 13

(indentation)


[error] 54-54: trailing spaces

(trailing-spaces)


[warning] 58-58: wrong indentation: expected 13 but found 15

(indentation)


[warning] 59-59: wrong indentation: expected 18 but found 19

(indentation)


[warning] 64-64: wrong indentation: expected 18 but found 19

(indentation)


[error] 66-66: trailing spaces

(trailing-spaces)


[error] 67-67: trailing spaces

(trailing-spaces)


[warning] 69-69: wrong indentation: expected 5 but found 7

(indentation)


[warning] 70-70: wrong indentation: expected 10 but found 11

(indentation)


[warning] 75-75: wrong indentation: expected 10 but found 11

(indentation)


[warning] 78-78: wrong indentation: expected 12 but found 13

(indentation)


[warning] 82-82: wrong indentation: expected 13 but found 15

(indentation)


[warning] 83-83: wrong indentation: expected 18 but found 19

(indentation)


[warning] 87-87: wrong indentation: expected 18 but found 19

(indentation)


[warning] 90-90: wrong indentation: expected 19 but found 21

(indentation)


[warning] 91-91: wrong indentation: expected 24 but found 25

(indentation)


[error] 95-95: trailing spaces

(trailing-spaces)


[warning] 98-98: wrong indentation: expected 5 but found 7

(indentation)


[warning] 103-103: wrong indentation: expected 10 but found 11

(indentation)


[warning] 106-106: wrong indentation: expected 12 but found 13

(indentation)


[warning] 110-110: wrong indentation: expected 13 but found 15

(indentation)


[warning] 111-111: wrong indentation: expected 18 but found 19

(indentation)


[warning] 116-116: wrong indentation: expected 18 but found 19

(indentation)


[warning] 119-119: wrong indentation: expected 10 but found 11

(indentation)


[warning] 120-120: wrong indentation: expected 12 but found 13

(indentation)


[warning] 123-123: wrong indentation: expected 14 but found 16

(indentation)


[warning] 127-127: wrong indentation: expected 10 but found 11

(indentation)


[warning] 128-128: wrong indentation: expected 12 but found 13

(indentation)


[warning] 131-131: wrong indentation: expected 13 but found 15

(indentation)


[warning] 132-132: wrong indentation: expected 18 but found 19

(indentation)


[warning] 136-136: wrong indentation: expected 18 but found 19

(indentation)


[warning] 139-139: wrong indentation: expected 20 but found 21

(indentation)


[warning] 142-142: wrong indentation: expected 22 but found 23

(indentation)


[warning] 148-148: wrong indentation: expected 5 but found 7

(indentation)


[warning] 149-149: wrong indentation: expected 10 but found 11

(indentation)


[warning] 154-154: wrong indentation: expected 10 but found 11

(indentation)


[warning] 157-157: wrong indentation: expected 12 but found 13

(indentation)


[error] 157-157: trailing spaces

(trailing-spaces)


[warning] 161-161: wrong indentation: expected 13 but found 15

(indentation)


[warning] 162-162: wrong indentation: expected 18 but found 19

(indentation)


[warning] 166-166: wrong indentation: expected 18 but found 19

(indentation)


[warning] 169-169: wrong indentation: expected 19 but found 21

(indentation)


[warning] 170-170: wrong indentation: expected 24 but found 25

(indentation)


[error] 173-173: trailing spaces

(trailing-spaces)


[error] 174-174: trailing spaces

(trailing-spaces)


[warning] 180-180: wrong indentation: expected 5 but found 7

(indentation)


[warning] 181-181: wrong indentation: expected 10 but found 11

(indentation)


[warning] 186-186: wrong indentation: expected 10 but found 11

(indentation)


[warning] 189-189: wrong indentation: expected 12 but found 13

(indentation)


[warning] 192-192: wrong indentation: expected 13 but found 15

(indentation)


[warning] 193-193: wrong indentation: expected 18 but found 19

(indentation)


[warning] 198-198: wrong indentation: expected 18 but found 19

(indentation)


[error] 200-200: trailing spaces

(trailing-spaces)


[warning] 203-203: wrong indentation: expected 5 but found 7

(indentation)


[error] 203-203: trailing spaces

(trailing-spaces)


[error] 204-204: trailing spaces

(trailing-spaces)


[warning] 206-206: wrong indentation: expected 5 but found 7

(indentation)


[warning] 207-207: wrong indentation: expected 10 but found 11

(indentation)


[warning] 212-212: wrong indentation: expected 10 but found 11

(indentation)


[warning] 215-215: wrong indentation: expected 12 but found 13

(indentation)


[error] 217-217: trailing spaces

(trailing-spaces)


[warning] 219-219: wrong indentation: expected 13 but found 15

(indentation)


[warning] 220-220: wrong indentation: expected 18 but found 19

(indentation)


[warning] 223-223: wrong indentation: expected 18 but found 19

(indentation)


[warning] 226-226: wrong indentation: expected 19 but found 21

(indentation)


[warning] 227-227: wrong indentation: expected 24 but found 25

(indentation)


[warning] 232-232: wrong indentation: expected 24 but found 25

(indentation)


[error] 234-234: trailing spaces

(trailing-spaces)


[warning] 237-237: wrong indentation: expected 6 but found 7

(indentation)


[warning] 241-241: wrong indentation: expected 10 but found 11

(indentation)


[error] 244-244: trailing spaces

(trailing-spaces)


[warning] 246-246: wrong indentation: expected 10 but found 11

(indentation)


[warning] 249-249: wrong indentation: expected 10 but found 11

(indentation)


[warning] 250-250: wrong indentation: expected 12 but found 13

(indentation)


[warning] 252-252: wrong indentation: expected 13 but found 15

(indentation)


[warning] 255-255: wrong indentation: expected 10 but found 11

(indentation)


[warning] 256-256: wrong indentation: expected 12 but found 13

(indentation)


[warning] 258-258: wrong indentation: expected 13 but found 15

(indentation)


[warning] 260-260: wrong indentation: expected 10 but found 11

(indentation)


[error] 262-262: no new line character at the end of file

(new-line-at-end-of-file)


[error] 262-262: trailing spaces

(trailing-spaces)

tests/cpp/null-library-function-cpp-test.yml

[error] 17-17: trailing spaces

(trailing-spaces)


[error] 21-21: trailing spaces

(trailing-spaces)


[error] 29-29: no new line character at the end of file

(new-line-at-end-of-file)

rules/c/security/null-library-function-c.yml

[warning] 25-25: wrong indentation: expected 5 but found 7

(indentation)


[warning] 26-26: wrong indentation: expected 10 but found 12

(indentation)


[warning] 29-29: wrong indentation: expected 12 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 17 but found 18

(indentation)


[warning] 35-35: wrong indentation: expected 17 but found 18

(indentation)


[warning] 38-38: wrong indentation: expected 10 but found 11

(indentation)


[warning] 40-40: wrong indentation: expected 11 but found 13

(indentation)


[error] 42-42: trailing spaces

(trailing-spaces)


[warning] 45-45: wrong indentation: expected 5 but found 7

(indentation)


[warning] 46-46: wrong indentation: expected 10 but found 11

(indentation)


[warning] 51-51: wrong indentation: expected 10 but found 11

(indentation)


[warning] 54-54: wrong indentation: expected 12 but found 13

(indentation)


[error] 54-54: trailing spaces

(trailing-spaces)


[warning] 58-58: wrong indentation: expected 13 but found 15

(indentation)


[warning] 59-59: wrong indentation: expected 18 but found 19

(indentation)


[warning] 64-64: wrong indentation: expected 18 but found 19

(indentation)


[error] 66-66: trailing spaces

(trailing-spaces)


[error] 67-67: trailing spaces

(trailing-spaces)


[warning] 69-69: wrong indentation: expected 5 but found 7

(indentation)


[warning] 70-70: wrong indentation: expected 10 but found 11

(indentation)


[warning] 75-75: wrong indentation: expected 10 but found 11

(indentation)


[warning] 78-78: wrong indentation: expected 12 but found 13

(indentation)


[warning] 82-82: wrong indentation: expected 13 but found 15

(indentation)


[warning] 83-83: wrong indentation: expected 18 but found 19

(indentation)


[warning] 87-87: wrong indentation: expected 18 but found 19

(indentation)


[warning] 90-90: wrong indentation: expected 19 but found 21

(indentation)


[warning] 91-91: wrong indentation: expected 24 but found 25

(indentation)


[error] 95-95: trailing spaces

(trailing-spaces)


[warning] 98-98: wrong indentation: expected 5 but found 7

(indentation)


[warning] 103-103: wrong indentation: expected 10 but found 11

(indentation)


[warning] 106-106: wrong indentation: expected 12 but found 13

(indentation)


[warning] 110-110: wrong indentation: expected 13 but found 15

(indentation)


[warning] 111-111: wrong indentation: expected 18 but found 19

(indentation)


[warning] 116-116: wrong indentation: expected 18 but found 19

(indentation)


[warning] 119-119: wrong indentation: expected 10 but found 11

(indentation)


[warning] 120-120: wrong indentation: expected 12 but found 13

(indentation)


[warning] 123-123: wrong indentation: expected 14 but found 16

(indentation)


[warning] 127-127: wrong indentation: expected 10 but found 11

(indentation)


[warning] 128-128: wrong indentation: expected 12 but found 13

(indentation)


[warning] 131-131: wrong indentation: expected 13 but found 15

(indentation)


[warning] 132-132: wrong indentation: expected 18 but found 19

(indentation)


[warning] 136-136: wrong indentation: expected 18 but found 19

(indentation)


[warning] 139-139: wrong indentation: expected 20 but found 21

(indentation)


[warning] 142-142: wrong indentation: expected 22 but found 23

(indentation)


[warning] 148-148: wrong indentation: expected 5 but found 7

(indentation)


[warning] 149-149: wrong indentation: expected 10 but found 11

(indentation)


[warning] 154-154: wrong indentation: expected 10 but found 11

(indentation)


[warning] 157-157: wrong indentation: expected 12 but found 13

(indentation)


[error] 157-157: trailing spaces

(trailing-spaces)


[warning] 161-161: wrong indentation: expected 13 but found 15

(indentation)


[warning] 162-162: wrong indentation: expected 18 but found 19

(indentation)


[warning] 166-166: wrong indentation: expected 18 but found 19

(indentation)


[warning] 169-169: wrong indentation: expected 19 but found 21

(indentation)


[warning] 170-170: wrong indentation: expected 24 but found 25

(indentation)


[error] 173-173: trailing spaces

(trailing-spaces)


[error] 174-174: trailing spaces

(trailing-spaces)


[warning] 180-180: wrong indentation: expected 5 but found 7

(indentation)


[warning] 181-181: wrong indentation: expected 10 but found 11

(indentation)


[warning] 186-186: wrong indentation: expected 10 but found 11

(indentation)


[warning] 189-189: wrong indentation: expected 12 but found 13

(indentation)


[warning] 192-192: wrong indentation: expected 13 but found 15

(indentation)


[warning] 193-193: wrong indentation: expected 18 but found 19

(indentation)


[warning] 198-198: wrong indentation: expected 18 but found 19

(indentation)


[error] 200-200: trailing spaces

(trailing-spaces)


[warning] 203-203: wrong indentation: expected 5 but found 7

(indentation)


[error] 203-203: trailing spaces

(trailing-spaces)


[error] 204-204: trailing spaces

(trailing-spaces)


[warning] 206-206: wrong indentation: expected 5 but found 7

(indentation)


[warning] 207-207: wrong indentation: expected 10 but found 11

(indentation)


[warning] 212-212: wrong indentation: expected 10 but found 11

(indentation)


[warning] 215-215: wrong indentation: expected 12 but found 13

(indentation)


[error] 217-217: trailing spaces

(trailing-spaces)


[warning] 219-219: wrong indentation: expected 13 but found 15

(indentation)


[warning] 220-220: wrong indentation: expected 18 but found 19

(indentation)


[warning] 223-223: wrong indentation: expected 18 but found 19

(indentation)


[warning] 226-226: wrong indentation: expected 19 but found 21

(indentation)


[warning] 227-227: wrong indentation: expected 24 but found 25

(indentation)


[warning] 232-232: wrong indentation: expected 24 but found 25

(indentation)


[error] 234-234: trailing spaces

(trailing-spaces)


[warning] 237-237: wrong indentation: expected 6 but found 7

(indentation)


[warning] 241-241: wrong indentation: expected 10 but found 11

(indentation)


[error] 244-244: trailing spaces

(trailing-spaces)


[warning] 246-246: wrong indentation: expected 10 but found 11

(indentation)


[warning] 249-249: wrong indentation: expected 10 but found 11

(indentation)


[warning] 250-250: wrong indentation: expected 12 but found 13

(indentation)


[warning] 252-252: wrong indentation: expected 13 but found 15

(indentation)


[warning] 255-255: wrong indentation: expected 10 but found 11

(indentation)


[warning] 256-256: wrong indentation: expected 12 but found 13

(indentation)


[warning] 258-258: wrong indentation: expected 13 but found 15

(indentation)


[warning] 260-260: wrong indentation: expected 10 but found 11

(indentation)


[error] 262-262: no new line character at the end of file

(new-line-at-end-of-file)


[error] 262-262: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
tests/c/null-library-function-c-test.yml (1)

4-9: Good error handling pattern!

The code correctly checks errno after fwrite and handles errors appropriately.

tests/__snapshots__/null-library-function-c-snapshot.yml (1)

1-94: Test patterns correctly demonstrate unsafe operations

The snapshots effectively capture problematic patterns that should trigger static analysis warnings:

  1. Assignment within function parameters
  2. Missing NULL checks
  3. Resource leaks
  4. Potential NULL pointer dereferences

These patterns are good negative examples for testing the static analyzer.

rules/c/security/null-library-function-c.yml (1)

1-11: LGTM! Well-documented rule configuration.

The rule metadata is well-defined with clear message, severity, and references to CWE-476.

@ganeshpatro321 ganeshpatro321 merged commit e11079e into coderabbitai:main Jan 20, 2025
1 check 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