Skip to content

Commit 3fd5e03

Browse files
committed
Add PrintDfg.qll
Adding this directly in the DataFlow module would expose it publicly via the `DataFlow::` prefix which does not seem desirable. We just want to be able to access it ourselves, so I've put it in its own file.
1 parent 8f9174e commit 3fd5e03

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ signature module InputSig<LocationSig Location> {
361361
* visible.
362362
*/
363363
default predicate isEvaluatingInOverlay() { none() }
364+
365+
/**
366+
* Gets a string to distinguish nodes that have the same location and toString value,
367+
* for use when generating graphs with `PrintDfg.qll`.
368+
*/
369+
default string nodeGetOrderDisambiguation(Node node) { result = "" }
364370
}
365371

366372
module Configs<LocationSig Location, InputSig<Location> Lang> {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Provides a module for implementing the `View DFG` query based on inputs to the data flow library.
3+
*/
4+
5+
private import codeql.util.Location
6+
private import codeql.dataflow.DataFlow as DF
7+
private import codeql.dataflow.TaintTracking as TT
8+
9+
module MakePrintDfg<
10+
LocationSig Location, DF::InputSig<Location> DataFlowLang,
11+
TT::InputSig<Location, DataFlowLang> TaintTrackingLang>
12+
{
13+
private import DataFlowLang
14+
private import codeql.util.PrintGraph as Pp
15+
16+
final private class FinalNode = Node;
17+
18+
private module PrintGraphInput implements Pp::InputSig<Location> {
19+
class Callable = DataFlowLang::DataFlowCallable;
20+
21+
class Node extends FinalNode {
22+
string getOrderDisambiguation() { result = DataFlowLang::nodeGetOrderDisambiguation(this) }
23+
24+
Callable getEnclosingCallable() { result = DataFlowLang::nodeGetEnclosingCallable(this) }
25+
}
26+
27+
predicate edge(Node node1, string label, Node node2) {
28+
simpleLocalFlowStep(node1, node2, _) and label = "value"
29+
or
30+
jumpStep(node1, node2) and label = "jump"
31+
or
32+
TaintTrackingLang::defaultAdditionalTaintStep(node1, node2, _) and label = "taint"
33+
or
34+
exists(ContentSet c |
35+
readStep(node1, c, node2) and label = "read[" + c.toString() + "]"
36+
or
37+
storeStep(node1, c, node2) and label = "store[" + c.toString() + "]"
38+
)
39+
or
40+
node1 = node2.(PostUpdateNode).getPreUpdateNode() and label = "post-update"
41+
}
42+
}
43+
44+
import Pp::PrintGraph<Location, PrintGraphInput>
45+
}

0 commit comments

Comments
 (0)