Skip to content

Commit e1a5eba

Browse files
author
Stephan Brandauer
committed
Java: automodel application mode: refactor varargs endpoint class to rely on normal argument node for nicer extracted examples
1 parent 650ff8d commit e1a5eba

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

java/ql/src/Telemetry/AutomodelApplicationModeCharacteristics.qll

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ newtype JavaRelatedLocationType = CallContext()
2424
newtype TApplicationModeEndpoint =
2525
TExplicitArgument(Call call, DataFlow::Node arg) {
2626
exists(Argument argExpr |
27-
arg.asExpr() = argExpr and not argExpr.isVararg() and call = argExpr.getCall()
27+
arg.asExpr() = argExpr and call = argExpr.getCall() and not argExpr.isVararg()
2828
)
2929
} or
3030
TInstanceArgument(Call call, DataFlow::Node arg) { arg = DataFlow::getInstanceArgument(call) } or
31-
TImplicitVarargsArray(Call call, DataFlow::ImplicitVarargsArray varargs, int idx) {
32-
varargs.getCall() = call and
33-
idx = min(Argument arg, int n | arg = call.getArgument(n) and arg.isVararg() | n)
31+
TImplicitVarargsArray(Call call, DataFlow::Node arg, int idx) {
32+
exists(Argument argExpr |
33+
arg.asExpr() = argExpr and
34+
call = argExpr.getCall() and
35+
argExpr.isVararg() and
36+
idx = min(int n | argExpr = call.getArgument(n) and argExpr.isVararg() | n)
37+
)
3438
}
3539

3640
/**
@@ -96,18 +100,18 @@ class InstanceArgument extends ApplicationModeEndpoint, TInstanceArgument {
96100
*/
97101
class ImplicitVarargsArray extends ApplicationModeEndpoint, TImplicitVarargsArray {
98102
Call call;
99-
DataFlow::ImplicitVarargsArray varargs;
103+
DataFlow::Node vararg;
100104
int idx;
101105

102-
ImplicitVarargsArray() { this = TImplicitVarargsArray(call, varargs, idx) }
106+
ImplicitVarargsArray() { this = TImplicitVarargsArray(call, vararg, idx) }
103107

104108
override predicate isArgOf(Call c, int i) { c = call and i = idx }
105109

106110
override Top asTop() { result = this.getCall() }
107111

108-
override DataFlow::Node asNode() { result = varargs }
112+
override DataFlow::Node asNode() { result = vararg }
109113

110-
override string toString() { result = varargs.toString() }
114+
override string toString() { result = vararg.toString() }
111115
}
112116

113117
/**
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
| Test.java:16:3:16:11 | reference | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@. | Test.java:16:3:16:11 | reference | CallContext | file://java.util.concurrent.atomic:1:1:1:1 | java.util.concurrent.atomic | package | file://AtomicReference:1:1:1:1 | AtomicReference | type | file://false:1:1:1:1 | false | subtypes | file://set:1:1:1:1 | set | name | file://(String):1:1:1:1 | (String) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://false:1:1:1:1 | false | isVarargsArray |
22
| Test.java:21:3:21:10 | supplier | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@. | Test.java:21:3:21:10 | supplier | CallContext | file://java.util.function:1:1:1:1 | java.util.function | package | file://Supplier:1:1:1:1 | Supplier | type | file://true:1:1:1:1 | true | subtypes | file://get:1:1:1:1 | get | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://false:1:1:1:1 | false | isVarargsArray |
3-
| Test.java:51:3:54:3 | new ..[] { .. } | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@. | Test.java:51:3:54:3 | walk(...) | CallContext | file://java.nio.file:1:1:1:1 | java.nio.file | package | file://Files:1:1:1:1 | Files | type | file://false:1:1:1:1 | false | subtypes | file://walk:1:1:1:1 | walk | name | file://(Path,FileVisitOption[]):1:1:1:1 | (Path,FileVisitOption[]) | signature | file://Argument[1]:1:1:1:1 | Argument[1] | input | file://true:1:1:1:1 | true | isVarargsArray |
3+
| Test.java:53:4:53:4 | o | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@. | Test.java:51:3:54:3 | walk(...) | CallContext | file://java.nio.file:1:1:1:1 | java.nio.file | package | file://Files:1:1:1:1 | Files | type | file://false:1:1:1:1 | false | subtypes | file://walk:1:1:1:1 | walk | name | file://(Path,FileVisitOption[]):1:1:1:1 | (Path,FileVisitOption[]) | signature | file://Argument[1]:1:1:1:1 | Argument[1] | input | file://true:1:1:1:1 | true | isVarargsArray |

java/ql/test/query-tests/Telemetry/AutomodelApplicationModeExtraction/Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public static int compareFiles(File f1, File f2) {
4747
);
4848
}
4949

50-
public static void FilesWalkExample(Path p) throws Exception {
50+
public static void FilesWalkExample(Path p, FileVisitOption o) throws Exception {
5151
Files.walk(
5252
p, // negative example (modeled as a taint step)
53-
FileVisitOption.FOLLOW_LINKS // the implicit varargs array is a candidate
53+
o // the implicit varargs array is a candidate
5454
);
5555
}
5656
}

0 commit comments

Comments
 (0)