Skip to content

Commit 42faabc

Browse files
committed
C#: Rename and restructure control flow graph entities
Follow a naming structure similar to the data flow library: - `ControlFlowNode` -> `ControlFlow::Node`. - `CallableEntryNode` -> `ControlFlow::Nodes::EntryNode`. - `CallableExitNode` -> `ControlFlow::Nodes::ExitNode`. - `ControlFlowEdgeType` -> `ControlFlow::SuccessorType`. - `ControlFlowEdgeSuccessor` -> `ControlFlow::SuccessorTypes::NormalSuccessor`. - `ControlFlowEdgeConditional -> ControlFlow::SuccessorTypes::ConditionalSuccessor`. - `ControlFlowEdgeBoolean` -> `ControlFlow::SuccessorTypes::BooleanSuccessor`. - `ControlFlowEdgeNullness` -> `ControlFlow::SuccessorTypes::NullnessSuccessor`. - `ControlFlowEdgeMatching` -> `ControlFlow::SuccessorTypes::MatchingSuccessor`. - `ControlFlowEdgeEmptiness` -> `ControlFlow::SuccessorTypes::EmptinessSuccessor`. - `ControlFlowEdgeReturn` -> `ControlFlow::SuccessorTypes::ReturnSuccessor`. - `ControlFlowEdgeBreak` -> `ControlFlow::SuccessorTypes::BreakSuccessor`. - `ControlFlowEdgeContinue` -> `ControlFlow::SuccessorTypes::ContinueSuccessor`. - `ControlFlowEdgeGotoLabel` -> `ControlFlow::SuccessorTypes::GotoLabelSuccessor`. - `ControlFlowEdgeGotoCase` -> `ControlFlow::SuccessorTypes::GotoCaseSuccessor`. - `ControlFlowEdgeGotoDefault` -> `ControlFlow::SuccessorTypes::GotoDefaultSuccessor`. - `ControlFlowEdgeException` -> `ControlFlow::SuccessorTypes::ExceptionSuccessor`
1 parent 8263b24 commit 42faabc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3010
-2940
lines changed

csharp/ql/src/API Abuse/Dispose.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ private import semmle.code.csharp.frameworks.system.web.UI
55

66
class DisposableType extends RefType {
77
DisposableType() {
8-
this.getABaseType+() = getSystemIDisposableInterface()
8+
this.getABaseType+() instanceof SystemIDisposableInterface
99
}
1010
}
1111

@@ -17,13 +17,13 @@ class DisposableField extends Field {
1717

1818
class WebControl extends RefType {
1919
WebControl() {
20-
this.getBaseClass*() = getSystemWebUIControlClass()
20+
this.getBaseClass*() instanceof SystemWebUIControlClass
2121
}
2222
}
2323

2424
class WebPage extends RefType {
2525
WebPage() {
26-
this.getBaseClass*() = getSystemWebUIPageClass()
26+
this.getBaseClass*() instanceof SystemWebUIPageClass
2727
}
2828
}
2929

csharp/ql/src/Bad Practices/Control-Flow/ConstantCondition.ql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import csharp
1515
import semmle.code.csharp.commons.Assertions
1616
import semmle.code.csharp.commons.Constants
17-
import ControlFlowGraph
1817

1918
/** A constant condition. */
2019
abstract class ConstantCondition extends Expr {
@@ -76,13 +75,13 @@ class ConstantNullnessCondition extends ConstantCondition {
7675
boolean b;
7776

7877
ConstantNullnessCondition() {
79-
forex(ControlFlowNode cfn |
78+
forex(ControlFlow::Node cfn |
8079
cfn = this.getAControlFlowNode() |
81-
exists(ControlFlowEdgeNullness t |
80+
exists(ControlFlow::SuccessorTypes::NullnessSuccessor t |
8281
exists(cfn.getASuccessorByType(t)) |
8382
if t.isNull() then b = true else b = false
8483
) and
85-
strictcount(ControlFlowEdgeType t | exists(cfn.getASuccessorByType(t))) = 1
84+
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
8685
)
8786
}
8887

@@ -99,13 +98,13 @@ class ConstantMatchingCondition extends ConstantCondition {
9998
boolean b;
10099

101100
ConstantMatchingCondition() {
102-
forex(ControlFlowNode cfn |
101+
forex(ControlFlow::Node cfn |
103102
cfn = this.getAControlFlowNode() |
104-
exists(ControlFlowEdgeMatching t |
103+
exists(ControlFlow::SuccessorTypes::MatchingSuccessor t |
105104
exists(cfn.getASuccessorByType(t)) |
106105
if t.isMatch() then b = true else b = false
107106
) and
108-
strictcount(ControlFlowEdgeType t | exists(cfn.getASuccessorByType(t))) = 1
107+
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
109108
)
110109
}
111110

csharp/ql/src/Bad Practices/ErroneousClassCompare.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ class StringComparison extends Expr {
3535
from StringComparison sc, PropertyAccess pa
3636
where sc.getAnOperand() instanceof StringLiteral
3737
and sc.getAnOperand() = pa
38-
and pa.getTarget() = getSystemTypeClass().getFullNameProperty()
38+
and pa.getTarget() = any(SystemTypeClass c).getFullNameProperty()
3939
select sc, "Erroneous class compare."

csharp/ql/src/Concurrency/Concurrency.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ class LockStmtBlock extends LockedBlock
102102
exists( LockStmt s | this=s.getBlock() )
103103
}
104104

105-
predicate isLockThis()
105+
override predicate isLockThis()
106106
{
107107
exists( LockStmt s | this=s.getBlock() and s.isLockThis() )
108108
}
109109

110-
Variable getLockVariable()
110+
override Variable getLockVariable()
111111
{
112112
exists( LockStmt s | this=s.getBlock() and result=s.getLockVariable() )
113113
}
114114

115-
Type getLockTypeObject()
115+
override Type getLockTypeObject()
116116
{
117117
exists( LockStmt s | this=s.getBlock() and result=s.getLockTypeObject() )
118118
}
@@ -138,17 +138,17 @@ class SynchronizedMethodBlock extends LockedBlock
138138
{
139139
exists( SynchronizedMethod m | this=m.getStatementBody() )
140140
}
141-
predicate isLockThis()
141+
override predicate isLockThis()
142142
{
143143
exists( SynchronizedMethod m | this=m.getStatementBody() and m.isLockThis() )
144144
}
145145

146-
Variable getLockVariable()
146+
override Variable getLockVariable()
147147
{
148148
none()
149149
}
150150

151-
Type getLockTypeObject()
151+
override Type getLockTypeObject()
152152
{
153153
exists( SynchronizedMethod m | this=m.getStatementBody() and result=m.getLockTypeObject() )
154154
}

csharp/ql/src/Concurrency/UnsynchronizedStaticAccess.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import csharp
1414
import DataMembers
1515
import ThreadCreation
16-
import ControlFlowGraph
1716

1817
predicate correctlySynchronized(CollectionMember c, Expr access) {
1918
access = c.getAReadOrWrite() and
@@ -24,9 +23,9 @@ predicate correctlySynchronized(CollectionMember c, Expr access) {
2423
)
2524
}
2625

27-
ControlFlowNode unlockedReachable(Callable a) {
26+
ControlFlow::Node unlockedReachable(Callable a) {
2827
result = a.getEntryPoint() or
29-
exists(ControlFlowNode mid | mid = unlockedReachable(a) |
28+
exists(ControlFlow::Node mid | mid = unlockedReachable(a) |
3029
not mid.getElement() instanceof LockingCall and
3130
result = mid.getASuccessor()
3231
)

csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import csharp
1515
import semmle.code.csharp.commons.ComparisonTest
16-
import semmle.code.csharp.controlflow.ControlFlowGraph::ControlFlowGraph
1716
import semmle.code.csharp.commons.StructuralComparison as SC
1817

1918
/** A structural comparison configuration for comparing the conditions of nested `for` loops. */
@@ -87,13 +86,13 @@ class NestedForLoopSameVariable extends ForStmt {
8786
}
8887

8988
/** Finds elements inside the outer loop that are no longer guarded by the loop invariant. */
90-
private ControlFlowNode getAnUnguardedNode()
89+
private ControlFlow::Node getAnUnguardedNode()
9190
{
9291
result.getElement().getParent+() = getOuterForStmt().getBody() and
9392
(
9493
result = this.getCondition().(ControlFlowElement).getAControlFlowExitNode().getAFalseSuccessor()
9594
or
96-
exists(ControlFlowNode mid | mid = getAnUnguardedNode() |
95+
exists(ControlFlow::Node mid | mid = getAnUnguardedNode() |
9796
mid.getASuccessor() = result and
9897
not exists(getAComparisonTest(result.getElement()))
9998
)

csharp/ql/src/Likely Bugs/Statements/UseBraces.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import csharp
1515

1616
// Iterate the control flow until we reach a Stmt
17-
Stmt findSuccessorStmt(ControlFlowGraph::ControlFlowNode n)
17+
Stmt findSuccessorStmt(ControlFlow::Node n)
1818
{
1919
result=n.getElement() or
2020
not n.getElement() instanceof Stmt and result=findSuccessorStmt(n.getASuccessor())

csharp/ql/src/Likely Bugs/UncheckedCastInEquals.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import csharp
1313
import semmle.code.csharp.frameworks.System
1414

15-
predicate nodeBeforeParameterAccess(ControlFlowGraph::ControlFlowNode node)
15+
predicate nodeBeforeParameterAccess(ControlFlow::Node node)
1616
{
1717
exists(EqualsMethod equals | equals.getBody() = node.getElement())
1818
or
19-
exists(EqualsMethod equals, Parameter param, ControlFlowGraph::ControlFlowNode mid |
19+
exists(EqualsMethod equals, Parameter param, ControlFlow::Node mid |
2020
equals.getParameter(0) = param and
2121
equals.getAChild*() = mid.getElement() and
2222
nodeBeforeParameterAccess(mid) and

csharp/ql/src/Performance/StringBuilderInLoop.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import csharp
1212
import semmle.code.csharp.frameworks.system.Text
1313

14-
from ObjectCreation creation, LoopStmt loop, ControlFlowGraph::ControlFlowNode loopEntryNode
14+
from ObjectCreation creation, LoopStmt loop, ControlFlow::Node loopEntryNode
1515
where creation.getType() instanceof SystemTextStringBuilderClass
1616
and loopEntryNode = loop.getBody().getAControlFlowEntryNode()
1717
and loop.getBody().getAChild*() = creation

csharp/ql/src/Security Features/CWE-384/AbandonSession.ql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
*/
1313

1414
import csharp
15-
import ControlFlowGraph
1615
import semmle.code.csharp.frameworks.system.web.Security
1716

18-
predicate loginMethod(Method m, ControlFlowEdgeType flowFrom)
17+
predicate loginMethod(Method m, ControlFlow::SuccessorType flowFrom)
1918
{
2019
(
2120
m = any(SystemWebSecurityMembershipClass c).getValidateUserMethod()
2221
or
2322
m = any(SystemWebSecurityFormsAuthenticationClass c).getAuthenticateMethod()
2423
)
2524
and
26-
flowFrom.(ControlFlowEdgeBoolean).getValue()=true
25+
flowFrom.(ControlFlow::SuccessorTypes::BooleanSuccessor).getValue()=true
2726
or
2827
m = any(SystemWebSecurityFormsAuthenticationClass c).getSignOutMethod()
2928
and
30-
flowFrom instanceof ControlFlowEdgeSuccessor
29+
flowFrom instanceof ControlFlow::SuccessorTypes::NormalSuccessor
3130
}
3231

3332
/** The `System.Web.SessionState.HttpSessionState` class. */
@@ -62,14 +61,14 @@ predicate sessionUse(MemberAccess ma)
6261
}
6362

6463
/** A control flow step that is not sanitised by a call to clear the session. */
65-
predicate controlStep(ControlFlowNode s1, ControlFlowNode s2)
64+
predicate controlStep(ControlFlow::Node s1, ControlFlow::Node s2)
6665
{
6766
s2 = s1.getASuccessor()
6867
and
6968
not sessionEndMethod(s2.getElement().(MethodCall).getTarget())
7069
}
7170

72-
from ControlFlowNode loginCall, Method loginMethod, ControlFlowNode sessionUse, ControlFlowEdgeType fromLoginFlow
71+
from ControlFlow::Node loginCall, Method loginMethod, ControlFlow::Node sessionUse, ControlFlow::SuccessorType fromLoginFlow
7372
where loginMethod = loginCall.getElement().(MethodCall).getTarget()
7473
and loginMethod(loginMethod, fromLoginFlow)
7574
and sessionUse(sessionUse.getElement())

0 commit comments

Comments
 (0)