Skip to content

Commit

Permalink
New rule: chromium-raw-ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Jul 25, 2023
1 parent c582334 commit 35ad247
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions assets/semgrep_rules/c/chromium-raw-ptr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
rules:
- id: chromium-raw-ptr
metadata:
author: Andrea Brancaleoni <[email protected]>
source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/c/chromium-raw-ptr.yaml
assignees: |
thypon
fmarier
patterns:
- pattern-either:
- pattern: $T * $V;
- pattern: $T * $V = ...;
- pattern-either:
- pattern-inside: class $CLASS { };
- pattern-inside: struct $STRUCT { };
fix-regex:
regex: ([a-zA-Z_][a-zA-Z0-9]+)\s*\*\s*
replacement: "raw_ptr<\\1> "
message: |
raw_ptr<T> should be used instead of T* in classes and structs (but not in local variables and function parameters).
References:
- https://groups.google.com/a/chromium.org/g/chromium-dev/c/vAEeVifyf78/m/SkBUc6PhBAAJ
- https://chromium.googlesource.com/chromium/src/+/refs/heads/main/base/memory/raw_ptr.md
languages:
- cpp
severity: WARNING
5 changes: 5 additions & 0 deletions t3sts/semgrep_rules/chromium-raw-ptr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
// ruleid: chromium-raw-ptr
Bar* bar_; // This should be rewritten to 'raw_ptr<Bar> bar_'.

};

0 comments on commit 35ad247

Please sign in to comment.