Skip to content

Commit 5e9826a

Browse files
authored
Merge pull request #26 from microsoft/jb1/lib/dataflowstack
DataFlowStack Common Library Init
2 parents 737dd9d + c92c212 commit 5e9826a

File tree

13 files changed

+488
-3
lines changed

13 files changed

+488
-3
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,30 @@ class DataFlowCall extends Expr instanceof Call {
253253
*/
254254
Expr getArgument(int n) { result = super.getArgument(n) }
255255

256+
/** Gets an argument to this call. */
257+
Expr getAnArgument(){ result = super.getAnArgument() }
258+
259+
/** Gets an argument to this call as a Node. */
260+
ArgumentNode getAnArgumentNode(){ result = this.getNode() }
261+
256262
/** Gets the data flow node corresponding to this call. */
257263
ExprNode getNode() { result.getExpr() = this }
258264

265+
/** Gets the data flow node corresponding to this call. (Alias of `getNode()`) */
266+
ExprNode getDataFlowNode() { result = this.getNode() }
267+
259268
/** Gets the enclosing callable of this call. */
260269
Function getEnclosingCallable() { result = this.getEnclosingFunction() }
270+
271+
/** Gets the target of the call, as best as makes sense for this kind of call.
272+
*
273+
* The precise meaning depends on the kind of call it is:
274+
* - For a call to a function, it’s the function being called.
275+
* - For a C++ method call, it’s the statically resolved method.
276+
* - For an Objective C message expression, it’s the statically resolved method, and it might not exist.
277+
* - For a variable call, it never exists.
278+
*/
279+
DataFlowCallable getARuntimeTarget(){ result = super.getTarget() }
261280
}
262281

263282
predicate isUnreachableInCall(Node n, DataFlowCall call) { none() } // stub implementation

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,13 @@ class DataFlowType = Type;
919919
/** A function call relevant for data flow. */
920920
class DataFlowCall extends CallInstruction {
921921
DataFlowCallable getEnclosingCallable() { result = this.getEnclosingFunction() }
922+
923+
// #43: Stub Implementation
924+
/** Gets an argument to this call as a Node. */
925+
ArgumentNode getAnArgumentNode(){ none() } // TODO: JB1 return an argument as a DataFlow ArgumentNode
926+
927+
/** Gets the target of the call, as a DataFlowCallable. */
928+
DataFlowCallable getARuntimeTarget(){ none() } // TODO getCallTarget() returns `Instruction`
922929
}
923930

924931
module IsUnreachableInCall {

csharp/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ upgrades: upgrades
88
dependencies:
99
codeql/controlflow: ${workspace}
1010
codeql/dataflow: ${workspace}
11+
codeql/dataflowstack: ${workspace}
1112
codeql/mad: ${workspace}
1213
codeql/ssa: ${workspace}
1314
codeql/threat-models: ${workspace}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
private import codeql.dataflow.DataFlow
3+
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
4+
5+
private import codeql.dataflowstack.DataFlowStack as DFS
6+
private import DFS::DataFlowStackMake<CsharpDataFlow> as DataFlowStackFactory
7+
8+
module DataFlowStackMake<DataFlowStackFactory::DataFlow::GlobalFlowSig Flow>{
9+
import DataFlowStackFactory::FlowStack<Flow>
10+
}
11+
12+
module BiStackAnalysisMake<DataFlowStackFactory::DataFlow::GlobalFlowSig FlowA, DataFlowStackFactory::DataFlow::GlobalFlowSig FlowB>{
13+
import DataFlowStackFactory::BiStackAnalysis<FlowA, FlowB>
14+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ abstract class DataFlowCall extends TDataFlowCall {
289289
/** Gets the argument at position `pos` of this call. */
290290
final ArgumentNode getArgument(ArgumentPosition pos) { result.argumentOf(this, pos) }
291291

292+
/** Gets an argument of this call. */
293+
final ArgumentNode getAnArgumentNode() { result.argumentOf(this, _) }
294+
292295
/** Gets a textual representation of this call. */
293296
abstract string toString();
294297

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ class DataFlowCall extends Expr {
334334
or
335335
not exists(this.getEnclosingFunction()) and result.asFileScope() = this.getFile()
336336
}
337+
338+
// #45 - Stub Implementation
339+
/** Gets an argument to this call as a Node. */
340+
ArgumentNode getAnArgumentNode(){ result = this.getArgument(_) }
341+
342+
/** Gets the target of the call, as a DataFlowCallable. */
343+
DataFlowCallable getARuntimeTarget(){ result.asCallable() = call.getACalleeIncludingExternals() }
337344
}
338345

339346
/** Holds if `e` is an expression that always has the same Boolean value `val`. */

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,13 @@ class DataFlowCall extends TDataFlowCall {
458458
) {
459459
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
460460
}
461+
462+
// #44: Stub Implementation
463+
/** Gets an argument to this call as a Node. */
464+
ArgumentNode getAnArgumentNode(){ none() } // TODO: JB1 return an argument as a DataFlow ArgumentNode
465+
466+
/** Gets the target of the call, as a DataFlowCallable. */
467+
DataFlowCallable getARuntimeTarget(){ none() }
461468
}
462469

463470
/** A source call, that is, a `Call`. */

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,13 @@ abstract class DataFlowCall extends TDataFlowCall {
13971397
) {
13981398
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
13991399
}
1400+
1401+
// #47: Stubs below
1402+
/** Gets an argument to this call as a Node. */
1403+
ArgumentNode getAnArgumentNode(){ none() } // TODO: JB1 return an argument as a DataFlow ArgumentNode
1404+
1405+
/** Gets the target of the call, as a DataFlowCallable. */
1406+
DataFlowCallable getARuntimeTarget(){ none() } // TODO
14001407
}
14011408

14021409
/** A call found in the program source (as opposed to a synthesised call). */

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ class DataFlowCall extends TDataFlowCall {
134134
) {
135135
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
136136
}
137+
138+
// #46: Stubs Below
139+
/** Gets an argument to this call as a Node. */
140+
ArgumentNode getAnArgumentNode(){ none() } // TODO: JB1 return an argument as a DataFlow ArgumentNode
141+
142+
/** Gets the target of the call, as a DataFlowCallable. */
143+
DataFlowCallable getARuntimeTarget(){ none() } // TODO
137144
}
138145

139146
/**

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ signature module InputSig {
5454
Node exprNode(DataFlowExpr e);
5555

5656
class DataFlowCall {
57+
58+
/**
59+
* Gets a run-time target of this call. A target is always a source
60+
* declaration, and if the callable has both CIL and source code, only
61+
* the source code version is returned.
62+
*/
63+
DataFlowCallable getARuntimeTarget();
64+
5765
/** Gets a textual representation of this element. */
5866
string toString();
5967

6068
DataFlowCallable getEnclosingCallable();
69+
70+
ArgumentNode getAnArgumentNode();
6171
}
6272

6373
class DataFlowCallable {
@@ -508,11 +518,11 @@ module DataFlowMake<InputSig Lang> {
508518
/** Gets the underlying Node. */
509519
Node getNode();
510520

511-
/** Gets a successor of this node, if any. */
512-
PathNode getASuccessor();
513-
514521
/** Holds if this node is a source. */
515522
predicate isSource();
523+
524+
/** Gets a successor of this node, if any. */
525+
PathNode getASuccessor();
516526
}
517527

518528
/**

0 commit comments

Comments
 (0)