FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

C#: Data flow for property patterns. by michaelnebel · Pull Request #22757 · github/codeql · GitHub

Repository navigation

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (1) .expected  (1) .md  (1) .qll  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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,4 @@
---
category: minorAnalysis
---
* Added support for data flow through property patterns in `is` expressions and `switch` cases.
This file contains hidden or 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
Expand Up @@ -2308,6 +2308,31 @@ private predicate readStepDelegateCall(Node node1, ContentSet c, OutNode node2)
)
}

/**
* Holds if data can flow from `node1` to `node2` via a property pattern.
*/
private predicate fieldOrPropertyPatternRead(Node node1, ContentSet c, Node node2) {
exists(PatternExpr pattern, LabeledPatternExpr label, FieldOrProperty f |
node1.asExpr() = pattern and
(
pattern.(RecursivePatternExpr).getPropertyPatterns().getPattern(_) = label
or
pattern.(PropertyPatternExpr).getPattern(_) = label
) and
c = f.getContentSet() and
f.getName() = label.getLabel()
|
node2.asExpr() = label.(RecursivePatternExpr)
or
node2.asExpr() = label.(PropertyPatternExpr)
or
exists(AssignableDefinitions::PatternDefinition lvd |
node2.(AssignableDefinitionNode).getDefinition() = lvd and
label.(BindingPatternExpr).getVariableDeclExpr() = lvd.getDeclaration()
)
)
}

/**
* Holds if data can flow from `node1` to `node2` via a read of content `c`.
*/
Expand All @@ -2319,6 +2344,8 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
or
fieldOrPropertyRead(node1.asExpr(), c, node2.asExpr())
or
fieldOrPropertyPatternRead(node1, c, node2)
or
dynamicPropertyRead(node1.asExpr(), c, node2.asExpr())
or
node2.asExpr().(AwaitExpr).getExpr() = node1.asExpr() and
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL