-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add refcounted-usage rule, also add .mm filetype * shared_ptr will be another rule
- Loading branch information
1 parent
1bcd54a
commit 19fa03f
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ rules: | |
- "*.h" | ||
- "*.hh" | ||
- "*.hcc" | ||
- "*.mm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ruleid: refcounted-usage | ||
class MyClass : public base::RefCounted<MyClass> { | ||
}; | ||
|
||
// ruleid: refcounted-usage | ||
class ThreadSafeClass : public base::RefCountedThreadSafe<ThreadSafeClass> { | ||
}; | ||
|
||
// ruleid: refcounted-usage | ||
base::RefCountedData<int> shared_integer(42); | ||
|
||
// ok: refcounted-usage | ||
class RegularClass { | ||
}; | ||
|
||
// ruleid: refcounted-usage | ||
using MyRefCountedType = base::RefCounted<SomeType>; | ||
|
||
// ruleid: refcounted-usage | ||
class NestedRefCounted : public base::RefCountedThreadSafe<NestedRefCounted> { | ||
// ruleid: refcounted-usage | ||
base::RefCountedData<std::string> nested_data_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
rules: | ||
- id: refcounted-usage | ||
metadata: | ||
author: Artem Chaikin | ||
source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/refcounted-usage.yaml | ||
assignees: | | ||
stoletheminerals | ||
thypon | ||
cdesouza-chromium | ||
bridiver | ||
pattern-either: | ||
- pattern: base::RefCounted<...> | ||
- pattern: base::RefCountedThreadSafe<...> | ||
- pattern: base::RefCountedData<...> | ||
message: "Reference counting is occasionally useful but is more often a sign that someone isn't thinking carefully about ownership. Use it when ownership is truly shared (for example, multiple tabs sharing the same renderer process), not for when lifetime management is difficult to reason about." | ||
languages: | ||
- generic | ||
paths: | ||
include: | ||
- "*.c" | ||
- "*.cpp" | ||
- "*.cc" | ||
- "*.h" | ||
- "*.hh" | ||
- "*.hcc" | ||
- "*.mm" | ||
severity: WARNING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ rules: | |
- "*.h" | ||
- "*.hpp" | ||
- "*.hh" | ||
- "*.mm" | ||
exclude: | ||
- test/ | ||
- "*.test.cc" | ||
|