Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
Dec 16, 2024
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 6, 2025
46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 8, 2025
7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 9, 2025
d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 10, 2025
2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 14, 2025
b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 20, 2025
65dce29
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 22, 2025
12bb3aa
httponly-false-csharp
ESS-ENN Jan 22, 2025
2c5ea88
use-of-md5-digest-utils-java
ESS-ENN Jan 22, 2025
d3067f1
removing use-of-md5-digest-utils and httponly-false-csharp
ESS-ENN Jan 22, 2025
56d4011
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 28, 2025
f7f1d72
Merge branch 'coderabbitai:main' into main
ESS-ENN Jan 29, 2025
0d53f8e
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 4, 2025
b622bca
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 6, 2025
67459bf
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 7, 2025
b8b2adb
Merge branch 'coderabbitai:main' into main
ESS-ENN Feb 18, 2025
9b29d0a
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 3, 2025
24510d4
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 4, 2025
6c6d229
Merge remote-tracking branch 'upstream/main' into main
ESS-ENN Mar 4, 2025
c5f0d85
Merge branch 'main' of https://github.com/ESS-ENN/ast-grep-essentials…
ESS-ENN Mar 4, 2025
4104e61
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 5, 2025
36b1114
Merge remote-tracking branch 'upstream/main' into main
ESS-ENN Mar 5, 2025
befc6b0
Merge branch 'main' of https://github.com/ESS-ENN/ast-grep-essentials…
ESS-ENN Mar 5, 2025
7bc886d
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 10, 2025
fc13546
Merge remote-tracking branch 'upstream/main' into main
ESS-ENN Mar 10, 2025
e4a1853
Merge branch 'main' of https://github.com/ESS-ENN/ast-grep-essentials…
ESS-ENN Mar 10, 2025
b6203b0
Merge branch 'coderabbitai:main' into main
ESS-ENN Mar 18, 2025
5327545
Merge remote-tracking branch 'upstream/main' into main
ESS-ENN Mar 20, 2025
bc580a5
std-return-data-cpp
ESS-ENN Mar 20, 2025
2b3fc12
std-vector-invalidation-cpp
ESS-ENN Mar 20, 2025
1991bb3
return-c-str-cpp
ESS-ENN Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions rules/c/security/return-c-str-c.yml

This file was deleted.

124 changes: 124 additions & 0 deletions rules/cpp/security/return-c-str-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
id: return-c-str-cpp
language: cpp
severity: warning
message: >-
"`$FUNC` returns a pointer to the memory owned by `$STR`. This pointer
is invalid after `$STR` goes out of scope, which can trigger a use after
free."
note: >-
[CWE-416] Use After Free
[REFERENCES]
- https://wiki.sei.cmu.edu/confluence/display/c/DCL30-C.+Declare+objects+with+appropriate+storage+durations
- https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP54-CPP.+Do+not+access+an+object+outside+of+its+lifetime

ast-grep-essentials: true

rule:
any:
- pattern: return basic_string<$TYPE>($$$).$METHOD();
- pattern: return std::basic_string<$TYPE>($$$).$METHOD();
- pattern: return string($$$).$METHOD();
- pattern: return std::string($$$).$METHOD();
- pattern: return wstring($$$).$METHOD();
- pattern: return std::wstring($$$).$METHOD();
- pattern: return $STR.$METHOD();
any:
- follows:
stopBy: end
all:
- not:
has:
stopBy: end
kind: storage_class_specifier
- any:
- kind: declaration
not:
pattern: $STR_VAL $STR = "$STRG";
- has:
pattern: $STR_VAL
- has:
stopBy: end
pattern: $STR
- inside:
stopBy: end
follows:
stopBy: end
all:
- not:
has:
stopBy: end
kind: storage_class_specifier
- any:
- kind: declaration
not:
pattern: $STR_VAL $STR = "$STRG";
- has:
pattern: $STR_VAL
- has:
pattern: $STR
- inside:
stopBy: end
follows:
stopBy: end
all:
- not:
has:
stopBy: end
kind: storage_class_specifier
- any:
- kind: pointer_declarator
not:
has:
stopBy: end
pattern: $STR_VAL $STR = "$STRG";
has:
kind: function_declarator
all:
- has:
stopBy: end
any:
- kind: qualified_identifier
- kind: type_identifier
regex: ^(basic_string<.*>|std::basic_string<.*>|string|std::string|wstring|std::wstring|string(.*)|std::string(.*)|wstring(.*)|std::wstring(.*)|basic_string<.*>(.*)|std::basic_string<.*>(.*))$
- has:
stopBy: end
pattern: $STR
- follows:
stopBy: end
all:
- not:
has:
stopBy: end
kind: storage_class_specifier
- any:
- kind: pointer_declarator
has:
kind: function_declarator
all:
- not:
has:
stopBy: end
pattern: $STR_VAL $STR = "$STRG";
- has:
stopBy: end
any:
- kind: qualified_identifier
- kind: type_identifier
regex: ^(basic_string<.*>|std::basic_string<.*>|string|std::string|wstring|std::wstring|string(.*)|std::string(.*)|wstring(.*)|std::wstring(.*)|basic_string<.*>(.*)|std::basic_string<.*>(.*))$
- has:
stopBy: end
pattern: $STR
- pattern: return $STR_VAL.$METHOD();
not:
all:
- has:
stopBy: end
kind: ERROR
- inside:
stopBy: end
kind: ERROR
constraints:
METHOD:
regex: ^(c_str|data)$
STR_VAL:
regex: ^(basic_string<.*>|std::basic_string<.*>|string|std::string|wstring|std::wstring|string(.*)|std::string(.*)|wstring(.*)|std::wstring(.*)|basic_string<.*>(.*)|std::basic_string<.*>(.*))$
85 changes: 85 additions & 0 deletions rules/cpp/security/std-return-data-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
id: std-return-data-cpp
language: cpp
severity: warning
message: >-
$FUNC` returns a pointer to the memory owned by `$VAR`. This pointer
is invalid after `$VAR` goes out of scope, which can trigger a use after
free.
note: >-
[CWE-416: Use After Free.
[REFERENCES]
- https://wiki.sei.cmu.edu/confluence/display/c/DCL30-C.+Declare+objects+with+appropriate+storage+durations

ast-grep-essentials: true

rule:
kind: return_statement
pattern: return $VAR.data();
all:
- inside:
stopBy: end
kind: function_definition
all:
- has:
nthChild: 1
pattern: $RETURN_TYPE
- has:
kind: pointer_declarator
- any:
- follows:
stopBy: end
all:
- has:
nthChild: 1
regex: ^(array<.*>|std::array<.*>|deque<.*>|std::deque<.*>|forward_list<.*>|std::forward_list<.*>|list<.*>|std::list<.*>|map<.*, .*>|std::map<.*, .*>|multimap<.*, .*>|std::multimap<.*, .*>|multiset<.*>|std::multiset<.*>|set<.*>|std::set<.*>|unordered_map<.*>|std::unordered_map<.*>|unordered_multimap<.*, .*>|std::unordered_multimap<.*, .*>|unordered_multiset<.*>|std::unordered_multiset<.*>|unordered_set<.*>|std::unordered_set<.*>|vector<.*>|std::vector<.*>)$
- has:
stopBy: end
# nthChild: 2
pattern: $VAR
- not:
inside:
stopBy: end
has:
kind: storage_class_specifier
- inside:
stopBy: end
kind: compound_statement
- inside:
stopBy: end
follows:
stopBy: end
all:
- has:
nthChild: 1
regex: ^(array<.*>|std::array<.*>|deque<.*>|std::deque<.*>|forward_list<.*>|std::forward_list<.*>|list<.*>|std::list<.*>|map<.*, .*>|std::map<.*, .*>|multimap<.*, .*>|std::multimap<.*, .*>|multiset<.*>|std::multiset<.*>|set<.*>|std::set<.*>|unordered_map<.*>|std::unordered_map<.*>|unordered_multimap<.*, .*>|std::unordered_multimap<.*, .*>|unordered_multiset<.*>|std::unordered_multiset<.*>|unordered_set<.*>|std::unordered_set<.*>|vector<.*>|std::vector<.*>)$
- has:
# nthChild: 2
stopBy: end
pattern: $VAR
- not:
inside:
stopBy: end
has:
kind: storage_class_specifier
- inside:
stopBy: end
kind: compound_statement
- inside:
stopBy: end
follows:
stopBy: end
kind: pointer_declarator
all:
- has:
stopBy: end
nthChild: 1
regex: ^(array<.*>|std::array<.*>|deque<.*>|std::deque<.*>|forward_list<.*>|std::forward_list<.*>|list<.*>|std::list<.*>|map<.*, .*>|std::map<.*, .*>|multimap<.*, .*>|std::multimap<.*, .*>|multiset<.*>|std::multiset<.*>|set<.*>|std::set<.*>|unordered_map<.*>|std::unordered_map<.*>|unordered_multimap<.*, .*>|std::unordered_multimap<.*, .*>|unordered_multiset<.*>|std::unordered_multiset<.*>|unordered_set<.*>|std::unordered_set<.*>|vector<.*>|std::vector<.*>)$
- has:
# nthChild: 2
stopBy: end
pattern: $VAR
- not:
inside:
stopBy: end
has:
kind: storage_class_specifier
150 changes: 150 additions & 0 deletions rules/cpp/security/std-vector-invalidation-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
id: std-vector-invalidation-cpp
language: cpp
severity: warning
message: >-
Modifying an `std::vector` while iterating over it could cause the
container to reallocate, triggering memory corruption.
note: >-
[CWE-416: Use After Free.
[REFERENCES]
- https://wiki.sei.cmu.edu/confluence/display/c/MEM30-C.+Do+not+access+freed+memory
- https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP54-CPP.+Do+not+access+an+object+outside+of+its+lifetime

ast-grep-essentials: true

rule:
kind: call_expression
all:
- any:
- pattern: $CONTAINER.erase($IT)
all:
- all:
- not:
follows:
stopBy: end
pattern: $CONTAINER.erase($IT)
- not:
precedes:
stopBy: end
pattern: $CONTAINER.erase($IT)
- not:
inside:
stopBy: end
kind: assignment_expression
has:
kind: identifier
pattern: $IT
nthChild: 1
- pattern: $CONTAINER.assign($$$)
- pattern: $CONTAINER.clear($$$)
- pattern: $CONTAINER.emplace_back($$$)
- pattern: $CONTAINER.insert($$$)
- pattern: $CONTAINER.resize($$$)
- pattern: $CONTAINER.push_back($$$)
- pattern: $CONTAINER.reserve($$$)
- pattern: $CONTAINER.shrink_to_fit($$$)
- pattern: $CONTAINER.resize($$$)
- pattern: $CONTAINER.pop_back($$$)
- not:
inside:
stopBy: end
kind: for_statement
has:
stopBy: end
any:
- kind: break_statement
- kind: continue_statement
- kind: return_statement
- kind: goto_statement
- inside:
stopBy: end
kind: for_statement
any:
- all:
- has:
kind: declaration
any:
- pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.begin()
- all:
- has:
kind: dependent_type
has:
stopBy: end
pattern: std::vector<$TY>::$IT_TYPE
- has:
stopBy: end
kind: init_declarator
all:
- has:
pattern: $IT
- has:
pattern: $CONTAINER.begin()
- has:
kind: binary_expression
any:
- pattern: $IT != $CONTAINER.end()
- has:
kind: update_expression
any:
- pattern: ++$IT
- pattern: $IT++
- all:
- has:
kind: declaration
any:
- pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.rbegin()
- has:
stopBy: end
pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.rbegin()
- all:
- has:
kind: dependent_type
has:
stopBy: end
pattern: std::vector<$TY>::$IT_TYPE
- has:
stopBy: end
kind: init_declarator
all:
- has:
pattern: $IT
- has:
pattern: $CONTAINER.rbegin()
- has:
kind: binary_expression
any:
- pattern: $IT != $CONTAINER.rend()
- has:
kind: update_expression
any:
- pattern: ++$IT
- pattern: $IT++
- all:
- has:
kind: declaration
any:
- pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.begin(), $IT_END = $CONTAINER.end()
- pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.rbegin(), $IT_END = $CONTAINER.rend()
- has:
stopBy: end
any:
- pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.begin(), $IT_END = $CONTAINER.end()
- pattern: std::vector<$TY>::$IT_TYPE $IT = $CONTAINER.rbegin(), $IT_END = $CONTAINER.rend()
- has:
kind: binary_expression
any:
- pattern: $IT != $IT_END
- has:
kind: update_expression
any:
- pattern: ++$IT
- pattern: $IT++
- all:
- not:
has:
stopBy: end
kind: ERROR
- not:
inside:
stopBy: end
kind: ERROR
Loading