Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 281f254

Browse files
author
Benjamin Muskalla
committed
Match enclosing unit without casting to specific nodes
1 parent bc10fd9 commit 281f254

7 files changed

Lines changed: 31 additions & 14 deletions

File tree

java/ql/src/utils/model-generator/CaptureSinkModels.ql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ class PropagateToSinkConfiguration extends TaintTracking::Configuration {
1616

1717
override predicate isSource(DataFlow::Node source) {
1818
source instanceof DataFlow::ParameterNode and
19-
source.asParameter().getCallable().isPublic() and
20-
source.asParameter().getCallable().getDeclaringType().isPublic() and
19+
source.getEnclosingCallable().isPublic() and
20+
source.getEnclosingCallable().getDeclaringType().isPublic() and
2121
isRelevantForModels(source.getEnclosingCallable())
2222
}
2323

2424
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) }
2525
}
2626

2727
string asInputArgument(DataFlow::Node source) {
28-
result = "Argument[" + source.asParameter().getPosition() + "]"
28+
exists(int pos |
29+
source.(DataFlow::ParameterNode).isParameterOf(_, pos) and
30+
result = "Argument[" + pos + "]"
31+
)
2932
}
3033

3134
string captureSink(Callable api) {

java/ql/src/utils/model-generator/CaptureSourceModels.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FromSourceConfiguration extends TaintTracking::Configuration {
2222
override predicate isSink(DataFlow::Node sink) {
2323
exists(Callable c |
2424
sink instanceof ReturnNodeExt and
25-
sink.asExpr().getEnclosingCallable() = c and
25+
sink.getEnclosingCallable() = c and
2626
c.isPublic() and
2727
c.fromSource()
2828
)
@@ -42,7 +42,7 @@ string captureSource(Callable api) {
4242
|
4343
config.hasFlow(src, sink) and
4444
specificSourceNode(sink, output, kind) and
45-
api = src.asExpr().getEnclosingCallable() and
45+
api = src.getEnclosingCallable() and
4646
result = asSourceModel(api, output, kind)
4747
)
4848
}

java/ql/src/utils/model-generator/CaptureSummaryModels.ql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ string captureQualifierFlow(Callable api) {
2828
}
2929

3030
string captureFieldFlow(Callable api) {
31-
exists(FieldAccess fa, ReturnNodeExt postUpdate |
31+
exists(FieldAccess fa, ReturnNodeExt returnNode |
3232
not (fa.getField().isStatic() and fa.getField().isFinal()) and
33-
postUpdate.getEnclosingCallable() = api and
33+
returnNode.getEnclosingCallable() = api and
34+
fa.getCompilationUnit() = api.getCompilationUnit() and
3435
isRelevantType(api.getReturnType()) and
3536
not api.getDeclaringType() instanceof EnumType and
36-
TaintTracking::localTaint(DataFlow::exprNode(fa), postUpdate)
37+
TaintTracking::localTaint(DataFlow::exprNode(fa), returnNode)
3738
|
38-
result = asTaintModel(api, "Argument[-1]", asOutput(api, postUpdate))
39+
result = asTaintModel(api, "Argument[-1]", asOutput(api, returnNode))
3940
)
4041
}
4142

@@ -59,7 +60,11 @@ class ParameterToFieldConfig extends TaintTracking::Configuration {
5960
}
6061

6162
override predicate isSink(DataFlow::Node sink) {
62-
exists(FieldAssignment a | a.getSource() = sink.asExpr())
63+
exists(FieldAssignment a |
64+
a.getSource() = sink.asExpr() and
65+
a.getDest().(VarAccess).getVariable().getCompilationUnit() =
66+
sink.getEnclosingCallable().getCompilationUnit()
67+
)
6368
}
6469
}
6570

java/ql/test/utils/model-generator/CaptureSummaryModels.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| p;Factory;false;create;(String);;Argument[0];Argument[-1];taint; |
22
| p;Factory;false;create;(String,int);;Argument[0];Argument[-1];taint; |
3+
| p;Factory;false;getValue;();;Argument[-1];ReturnValue;taint; |
34
| p;FinalClass;false;returnsInput;(String);;Argument[0];ReturnValue;taint; |
45
| p;FluentAPI;false;returnsThis;(String);;Argument[-1];ReturnValue;value; |
56
| p;ImmutablePojo;false;ImmutablePojo;(String,int);;Argument[0];Argument[-1];taint; |

java/ql/test/utils/model-generator/p/Factory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ private Factory(String value, int intValue) {
1919
this.intValue = intValue;
2020
}
2121

22+
public String getValue() {
23+
return value;
24+
}
25+
26+
public int getIntValue() {
27+
return intValue;
28+
}
29+
2230
}

java/ql/test/utils/model-generator/p/ImmutablePojo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public String getValue() {
1515
return value;
1616
}
1717

18+
public long getX() {
19+
return x;
20+
}
21+
1822
public String or(String defaultValue) {
1923
return value != null ? value : defaultValue;
2024
}

java/ql/test/utils/model-generator/p/MultipleImpls.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package p;
22

3-
import java.io.File;
4-
import java.io.FileFilter;
5-
import java.io.IOException;
6-
import java.nio.file.Files;
73
import java.util.concurrent.Callable;
84

95
public class MultipleImpls {

0 commit comments

Comments
 (0)