Skip to content

Commit c173d9a

Browse files
author
Stephan Brandauer
committed
Java: automodel application mode: generate models for overridden method candidates
1 parent 3121949 commit c173d9a

7 files changed

+42
-42
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ newtype TApplicationModeEndpoint =
3737
)
3838
} or
3939
TMethodCall(Call call) { not call instanceof ConstructorCall } or
40-
TOverriddenParameter(Parameter p) {
40+
TOverriddenParameter(Parameter p, Method overriddenMethod) {
4141
not p.getCallable().callsConstructor(_) and
42-
p.getCallable().(Method).overrides(_)
42+
p.getCallable().(Method).overrides(overriddenMethod)
4343
}
4444

4545
/**
@@ -174,18 +174,16 @@ class MethodCall extends ApplicationModeEndpoint, TMethodCall {
174174

175175
class OverriddenParameter extends ApplicationModeEndpoint, TOverriddenParameter {
176176
Parameter p;
177+
Method overriddenMethod;
177178

178-
OverriddenParameter() { this = TOverriddenParameter(p) }
179+
OverriddenParameter() { this = TOverriddenParameter(p, overriddenMethod) }
179180

180181
override Callable getCallable() {
181-
// XXX: we're returning the overriding callable here. This means that the
182-
// candidate model will be about the overriding method, not the overridden
183-
// method (which is more general).
184-
// Doing it this way:
185-
// - (+) makes the decision easier for the user
186-
// - (+) is simplest, implementation-wise
187-
// - (-) produces a less general model
188-
result = p.getCallable()
182+
// NB: we're returning the overridden callable here. This means that the
183+
// candidate model will be about the overridden method, not the overriding
184+
// method. This is a more general model, that also applies to other
185+
// subclasses of the overridden class.
186+
result = overriddenMethod
189187
}
190188

191189
override Call getCall() { none() }
@@ -269,8 +267,8 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
269267
additional predicate sinkSpec(
270268
Endpoint e, string package, string type, string name, string signature, string ext, string input
271269
) {
272-
ApplicationModeGetCallable::getCallable(e).hasQualifiedName(package, type, name) and
273-
signature = ExternalFlow::paramsString(ApplicationModeGetCallable::getCallable(e)) and
270+
e.getCallable().hasQualifiedName(package, type, name) and
271+
signature = ExternalFlow::paramsString(e.getCallable()) and
274272
ext = "" and
275273
input = e.getMaDInput()
276274
}
@@ -279,8 +277,8 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
279277
Endpoint e, string package, string type, string name, string signature, string ext,
280278
string output
281279
) {
282-
ApplicationModeGetCallable::getCallable(e).hasQualifiedName(package, type, name) and
283-
signature = ExternalFlow::paramsString(ApplicationModeGetCallable::getCallable(e)) and
280+
e.getCallable().hasQualifiedName(package, type, name) and
281+
signature = ExternalFlow::paramsString(e.getCallable()) and
284282
ext = "" and
285283
output = e.getMaDOutput()
286284
}

java/ql/automodel/test/AutomodelApplicationModeExtraction/AutomodelApplicationModeExtractCandidates.expected

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
| Test.java:46:10:48:3 | compareTo(...) | known sanitizer\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:46:10:48:3 | compareTo(...) | CallContext | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://false:1:1:1:1 | false | isVarargsArray |
2-
| Test.java:47:4:47:5 | f2 | known non-sink\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:46:10:48:3 | compareTo(...) | CallContext | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
3-
| Test.java:53:4:53:4 | p | taint step\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:52:3:57: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[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
1+
| Test.java:47:10:49:3 | compareTo(...) | known sanitizer\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:47:10:49:3 | compareTo(...) | CallContext | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://false:1:1:1:1 | false | isVarargsArray |
2+
| Test.java:48:4:48:5 | f2 | known non-sink\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:47:10:49:3 | compareTo(...) | CallContext | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
3+
| Test.java:54:4:54:4 | p | taint step\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:53:3:58: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[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
4+
| Test.java:66:7:66:18 | this <constr(this)> | exception\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:66:7:66:18 | super(...) | CallContext | file://java.lang:1:1:1:1 | java.lang | package | file://Exception:1:1:1:1 | Exception | type | file://true:1:1:1:1 | true | subtypes | file://Exception:1:1:1:1 | Exception | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| Test.java:27:4:27:9 | source | path-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:26:3:30:3 | copy(...) | 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://copy:1:1:1:1 | copy | name | file://(Path,Path,CopyOption[]):1:1:1:1 | (Path,Path,CopyOption[]) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
2-
| Test.java:28:4:28:9 | target | path-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:26:3:30:3 | copy(...) | 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://copy:1:1:1:1 | copy | name | file://(Path,Path,CopyOption[]):1:1:1:1 | (Path,Path,CopyOption[]) | signature | file://Argument[1]:1:1:1:1 | Argument[1] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
3-
| Test.java:35:4:35:11 | openPath | path-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:34:10:36:3 | newInputStream(...) | 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://newInputStream:1:1:1:1 | newInputStream | name | file://(Path,OpenOption[]):1:1:1:1 | (Path,OpenOption[]) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
4-
| Test.java:61:3:61:20 | getInputStream(...) | remote\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:61:3:61:20 | getInputStream(...) | CallContext | file://java.net:1:1:1:1 | java.net | package | file://URLConnection:1:1:1:1 | URLConnection | type | file://true:1:1:1:1 | true | subtypes | file://getInputStream:1:1:1:1 | getInputStream | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://false:1:1:1:1 | false | isVarargsArray |
1+
| Test.java:28:4:28:9 | source | path-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:27:3:31:3 | copy(...) | 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://copy:1:1:1:1 | copy | name | file://(Path,Path,CopyOption[]):1:1:1:1 | (Path,Path,CopyOption[]) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
2+
| Test.java:29:4:29:9 | target | path-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:27:3:31:3 | copy(...) | 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://copy:1:1:1:1 | copy | name | file://(Path,Path,CopyOption[]):1:1:1:1 | (Path,Path,CopyOption[]) | signature | file://Argument[1]:1:1:1:1 | Argument[1] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
3+
| Test.java:36:4:36:11 | openPath | path-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:35:10:37:3 | newInputStream(...) | 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://newInputStream:1:1:1:1 | newInputStream | name | file://(Path,OpenOption[]):1:1:1:1 | (Path,OpenOption[]) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://false:1:1:1:1 | false | isVarargsArray |
4+
| Test.java:62:3:62:20 | getInputStream(...) | remote\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@. | Test.java:62:3:62:20 | getInputStream(...) | CallContext | file://java.net:1:1:1:1 | java.net | package | file://URLConnection:1:1:1:1 | URLConnection | type | file://true:1:1:1:1 | true | subtypes | file://getInputStream:1:1:1:1 | getInputStream | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://false:1:1:1:1 | false | isVarargsArray |

java/ql/automodel/test/AutomodelApplicationModeExtraction/PluginImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import hudson.Plugin;
22

3-
public class PluginImpl implements Plugin {
3+
public class PluginImpl extends Plugin {
44
@Override
55
public void configure(String name, String value) {
66
// ...

java/ql/automodel/test/AutomodelApplicationModeExtraction/Test.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.codeql.test;
22

33
import java.io.InputStream;
4+
import java.io.PrintWriter;
45
import java.nio.file.CopyOption;
56
import java.nio.file.Files;
67
import java.nio.file.Path;
@@ -47,7 +48,7 @@ public static int compareFiles(File f1, File f2) {
4748
f2 // negative example (modeled as not a sink)
4849
);
4950
}
50-
51+
5152
public static void FilesWalkExample(Path p, FileVisitOption o) throws Exception {
5253
Files.walk( // the call is a source candidate
5354
p, // negative example (modeled as a taint step)
@@ -62,8 +63,8 @@ public static void WebSocketExample(URLConnection c) throws Exception {
6263
}
6364
}
6465

65-
class OverrideTest {
66-
public boolean equals(Object o) { // o is a source candidate because it overrides an existing method
67-
return false;
66+
class OverrideTest extends Exception {
67+
public void printStackTrace(PrintWriter writer) { // writer is a source candidate because it overrides an existing method
68+
return;
6869
}
6970
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package hudson;
22

3-
public interface Plugin {
4-
public void configure(String name, String value);
3+
public class Plugin {
4+
public void configure(String name, String value) {}
55
}

0 commit comments

Comments
 (0)