Skip to content

Commit 906a478

Browse files
committed
Data flow: Add LambdaArgs node
1 parent 7265884 commit 906a478

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

shared/dataflow/codeql/dataflow/internal/ContentDataFlowImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ module MakeImplContentDataFlow<LocationSig Location, InputSig<Location> Lang> {
216216

217217
private predicate readStep(Node node1, State state1, ContentSet c, Node node2, ReadState state2) {
218218
exists(int size |
219-
readSet(node1, c, node2) and
219+
readSet(any(NodeEx n1 | n1.asNode() = node1), c, any(NodeEx n2 | n2.asNode() = node2)) and // todo
220220
ContentConfig::isRelevantContent(c) and
221221
state2.decode(size + 1, true)
222222
|

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
477477
hasReadStep(c)
478478
}
479479

480-
// pragma[nomagic]
481-
// private predicate viableReturnPosOutEx(DataFlowCall call, ReturnPosition pos, NodeEx out) {
482-
// viableReturnPosOut(call, pos, out.asNode())
483-
// }
484-
// pragma[nomagic]
485-
// private predicate viableParamArgEx(DataFlowCall call, ParamNodeEx p, ArgNodeEx arg) {
486-
// viableParamArg(call, p.asNode(), arg.asNode())
487-
// }
488480
/**
489481
* Holds if field flow should be used for the given configuration.
490482
*/
@@ -2896,15 +2888,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
28962888

28972889
predicate isHidden() {
28982890
not Config::includeHiddenNodes() and
2899-
(
2900-
hiddenNode(this.getNodeEx().asNode()) and
2901-
not this.isSource() and
2902-
not this instanceof PathNodeSink
2903-
or
2904-
this.getNodeEx() instanceof TNodeImplicitRead
2905-
or
2906-
hiddenNode(this.getNodeEx().asParamReturnNode())
2907-
)
2891+
hiddenNode(this.getNodeEx()) and
2892+
not this.isSource() and
2893+
not this instanceof PathNodeSink
29082894
}
29092895

29102896
/** Gets a textual representation of this element. */

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
891891
or
892892
result = this.asLambdaMallocNode().toString() + " [LambdaMalloc]"
893893
or
894+
result = this.asLambdaArgsNode().toString() + " [LambdaArgs]"
895+
or
894896
result = this.asLambdaInstancePostUpdateNode().toString() + " [LambdaPostUpdate]"
895897
or
896898
exists(DataFlowCall synthcall, ArgumentPosition apos, boolean isPost |
@@ -914,6 +916,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
914916

915917
Node asLambdaMallocNode() { this = TNodeLambdaMalloc(result) }
916918

919+
Node asLambdaArgsNode() { this = TNodeLambdaArgs(result) }
920+
917921
predicate isLambdaArgNode(DataFlowCall synthcall, ArgumentPosition apos, boolean isPost) {
918922
this = TNodeLambdaArg(synthcall, apos, isPost)
919923
}
@@ -929,6 +933,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
929933
or
930934
this = TNodeLambdaMalloc(result)
931935
or
936+
this = TNodeLambdaArgs(result)
937+
or
932938
exists(DataFlowCall synthcall |
933939
this = TNodeLambdaArg(synthcall, _, _) and
934940
lambdaCreation(result, _, _, synthcall)
@@ -955,6 +961,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
955961
or
956962
nodeDataFlowType(this.asLambdaMallocNode(), result)
957963
or
964+
nodeDataFlowType(this.asLambdaArgsNode(), result)
965+
or
958966
exists(
959967
DataFlowCall synthcall, ArgumentPosition apos, DataFlowCallable c, ParameterNode p,
960968
ParameterPosition ppos
@@ -1117,9 +1125,14 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
11171125
}
11181126

11191127
cached
1120-
predicate hiddenNode(Node n) {
1121-
// todo: add all lambda nodes here after end debugging
1122-
nodeIsHidden(n)
1128+
predicate hiddenNode(NodeEx n) {
1129+
nodeIsHidden(n.asNode()) or
1130+
n.isImplicitReadNode(_) or
1131+
exists(n.asLambdaInstancePostUpdateNode()) or
1132+
exists(n.asLambdaMallocNode()) or
1133+
exists(n.asLambdaArgsNode()) or
1134+
n.isLambdaArgNode(_, _, _) or
1135+
hiddenNode(any(NodeEx p | n.asParamReturnNode() = p.asNode()))
11231136
}
11241137

11251138
cached
@@ -1788,10 +1801,15 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
17881801
or
17891802
//read step from malloc to args
17901803
//lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c, DataFlowCall synthCall)
1791-
exists(DataFlowCall synthcall, LambdaCallKind k, ArgumentPosition apos |
1792-
lambdaCreation(node1.asLambdaMallocNode(), k, _, synthcall) and
1793-
node2.isLambdaArgNode(synthcall, apos, false) and
1804+
exists(Node lambda, DataFlowCall synthcall, LambdaCallKind k, ArgumentPosition apos |
1805+
lambdaCreation(lambda, k, _, synthcall) and
1806+
lambda = node1.asLambdaArgsNode() and
17941807
c.getAReadContent() = getLambdaArgumentContent(k, apos)
1808+
|
1809+
node2.isLambdaArgNode(synthcall, apos, false)
1810+
or
1811+
node2.asLambdaMallocNode() = lambda and
1812+
node2.(ArgNodeEx).argumentOf(_, apos)
17951813
)
17961814
}
17971815

@@ -2030,12 +2048,13 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
20302048
} or
20312049
TNodeLambdaInstancePostUpdate(ParameterNode pre) { isLambdaInstanceParameter(pre) } or
20322050
TNodeLambdaMalloc(Node lambda) { lambdaCreation(lambda, _, _, _) } or
2051+
TNodeLambdaArgs(Node lambda) { lambdaCreation(lambda, _, _, _) } or
20332052
TNodeLambdaArg(DataFlowCall synthcall, ArgumentPosition apos, Boolean ispost) {
20342053
exists(DataFlowCallable c, ParameterNode p, ParameterPosition ppos |
20352054
lambdaCreation(_, _, c, synthcall) and
20362055
isParameterNode(p, c, ppos) and
2037-
not isLambdaInstanceParameter(p) and
20382056
parameterMatch(ppos, apos) and
2057+
not isLambdaInstanceParameter(p) and
20392058
exists(ispost)
20402059
)
20412060
}
@@ -2077,7 +2096,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
20772096
model = ""
20782097
)
20792098
or
2080-
LambdaFlow::lambdaFlowsToPostUpdate(node2.asLambdaMallocNode(), node1.asNode()) and
2099+
LambdaFlow::lambdaFlowsToPostUpdate(node2.asLambdaArgsNode(), node1.asNode()) and
20812100
model = ""
20822101
}
20832102

0 commit comments

Comments
 (0)