Skip to content

Commit 917179b

Browse files
committed
C#: Exclude patterns without variable declarations and top level declarations as local step targets.
1 parent bf66d2c commit 917179b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,16 @@ module SsaFlow {
520520

521521
/** Provides predicates related to local data flow. */
522522
module LocalFlow {
523+
/**
524+
* Holds if the pattern `e` is a top level variable pattern expression or
525+
* if the pattern doesn't contain any variable pattern expressions.
526+
*/
527+
private predicate basicPattern(PatternExpr e) {
528+
e instanceof VariablePatternExpr
529+
or
530+
not exists(VariablePatternExpr vpe | e.getAChild*() = vpe)
531+
}
532+
523533
class LocalExprStepConfiguration extends ControlFlowReachabilityConfiguration {
524534
LocalExprStepConfiguration() { this = "LocalExprStepConfiguration" }
525535

@@ -615,14 +625,16 @@ module LocalFlow {
615625
scope =
616626
any(IsExpr ie |
617627
e1 = ie.getExpr() and
618-
e2 = ie.getPattern()
628+
e2 = ie.getPattern() and
629+
not basicPattern(e2)
619630
)
620631
or
621632
isSuccessor = true and
622633
scope =
623634
any(Switch e |
624635
e1 = e.getExpr() and
625-
e2 = e.getACase().getPattern()
636+
e2 = e.getACase().getPattern() and
637+
not basicPattern(e2)
626638
)
627639
or
628640
isSuccessor = false and

0 commit comments

Comments
 (0)