Skip to content

Commit 47f6850

Browse files
committed
Dataflow: Postpone typeflow calledge pruning until stage 3.
1 parent f5a4b79 commit 47f6850

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,8 @@ module MakeImpl<InputSig Lang> {
11851185

11861186
bindingset[typ, contentType]
11871187
predicate typecheckStore(Typ typ, DataFlowType contentType);
1188+
1189+
default predicate enableTypeFlow() { any() }
11881190
}
11891191

11901192
module Stage<StageParam Param> implements StageSig {
@@ -1541,6 +1543,8 @@ module MakeImpl<InputSig Lang> {
15411543
}
15421544

15431545
private module FwdTypeFlowInput implements TypeFlowInput {
1546+
predicate enableTypeFlow = Param::enableTypeFlow/0;
1547+
15441548
predicate relevantCallEdgeIn(DataFlowCall call, DataFlowCallable c) {
15451549
flowIntoCallApa(call, c, _, _, _, _)
15461550
}
@@ -1845,6 +1849,8 @@ module MakeImpl<InputSig Lang> {
18451849
}
18461850

18471851
private module RevTypeFlowInput implements TypeFlowInput {
1852+
predicate enableTypeFlow = Param::enableTypeFlow/0;
1853+
18481854
predicate relevantCallEdgeIn(DataFlowCall call, DataFlowCallable c) {
18491855
flowOutOfCallAp(call, c, _, _, _, _)
18501856
}
@@ -2306,6 +2312,8 @@ module MakeImpl<InputSig Lang> {
23062312

23072313
bindingset[typ, contentType]
23082314
predicate typecheckStore(Typ typ, DataFlowType contentType) { any() }
2315+
2316+
predicate enableTypeFlow() { none() }
23092317
}
23102318

23112319
private module Stage2 implements StageSig {

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,8 @@ module MakeImplCommon<InputSig Lang> {
971971
}
972972

973973
signature module TypeFlowInput {
974+
predicate enableTypeFlow();
975+
974976
/** Holds if the edge is possibly needed in the direction `call` to `c`. */
975977
predicate relevantCallEdgeIn(DataFlowCall call, DataFlowCallable c);
976978

@@ -1036,24 +1038,27 @@ module MakeImplCommon<InputSig Lang> {
10361038
*/
10371039
pragma[nomagic]
10381040
private predicate trackedArgTypeCand(ArgNode arg) {
1039-
exists(ParamNode p, DataFlowType at, DataFlowType pt |
1040-
at = getNodeType(arg) and
1041-
pt = getNodeType(p) and
1042-
relevantCallEdge(_, _, arg, p) and
1043-
typeStrongerThan0(pt, at)
1044-
)
1045-
or
1046-
exists(ParamNode p, DataFlowType at, DataFlowType pt |
1047-
at = getNodeType(arg) and
1048-
pt = getNodeType(p) and
1049-
paramMustFlow(p, arg) and
1050-
relevantCallEdge(_, _, arg, _) and
1051-
typeStrongerThan0(at, pt)
1052-
)
1053-
or
1054-
exists(ParamNode p |
1055-
trackedParamTypeCand(p) and
1056-
relevantCallEdge(_, _, arg, p)
1041+
Input::enableTypeFlow() and
1042+
(
1043+
exists(ParamNode p, DataFlowType at, DataFlowType pt |
1044+
at = getNodeType(arg) and
1045+
pt = getNodeType(p) and
1046+
relevantCallEdge(_, _, arg, p) and
1047+
typeStrongerThan0(pt, at)
1048+
)
1049+
or
1050+
exists(ParamNode p, DataFlowType at, DataFlowType pt |
1051+
at = getNodeType(arg) and
1052+
pt = getNodeType(p) and
1053+
paramMustFlow(p, arg) and
1054+
relevantCallEdge(_, _, arg, _) and
1055+
typeStrongerThan0(at, pt)
1056+
)
1057+
or
1058+
exists(ParamNode p |
1059+
trackedParamTypeCand(p) and
1060+
relevantCallEdge(_, _, arg, p)
1061+
)
10571062
)
10581063
}
10591064

@@ -1276,10 +1281,14 @@ module MakeImplCommon<InputSig Lang> {
12761281
predicate typeFlowValidEdgeIn(DataFlowCall call, DataFlowCallable c, boolean cc) {
12771282
Input::relevantCallEdgeIn(call, c) and
12781283
cc = [true, false] and
1279-
forall(ArgNode arg, ParamNode p |
1280-
callEdge(call, c, arg, p) and trackedArgType(arg) and paramMustFlow(_, arg)
1281-
|
1282-
validArgParamIn(arg, p, cc)
1284+
(
1285+
not Input::enableTypeFlow()
1286+
or
1287+
forall(ArgNode arg, ParamNode p |
1288+
callEdge(call, c, arg, p) and trackedArgType(arg) and paramMustFlow(_, arg)
1289+
|
1290+
validArgParamIn(arg, p, cc)
1291+
)
12831292
)
12841293
}
12851294

@@ -1313,8 +1322,12 @@ module MakeImplCommon<InputSig Lang> {
13131322
*/
13141323
predicate typeFlowValidEdgeOut(DataFlowCall call, DataFlowCallable c) {
13151324
Input::relevantCallEdgeOut(call, c) and
1316-
forall(ArgNode arg, ParamNode p | callEdge(call, c, arg, p) and trackedParamType(p) |
1317-
validArgParamOut(arg, p)
1325+
(
1326+
not Input::enableTypeFlow()
1327+
or
1328+
forall(ArgNode arg, ParamNode p | callEdge(call, c, arg, p) and trackedParamType(p) |
1329+
validArgParamOut(arg, p)
1330+
)
13181331
)
13191332
}
13201333
}

0 commit comments

Comments
 (0)