Skip to content

Commit b53fa0f

Browse files
committed
Java: Ensure that it is the callable for the model origin that carries the comment containing the model.
1 parent a8549d2 commit b53fa0f

File tree

9 files changed

+31
-25
lines changed

9 files changed

+31
-25
lines changed

java/ql/test/TestUtilities/InlineMadTest.qll

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,53 @@ import java
22

33
private signature module InlineMadTestLangSig {
44
/**
5-
* Gets a relevant code comment, if any.
5+
* Gets a relevant code comment for `c`, if any.
66
*/
7-
string getComment();
7+
string getComment(Callable c);
88
}
99

1010
signature module InlineMadTestConfigSig {
1111
/**
12-
* Gets the kind of the captured model.
12+
* Gets the kind of a captured model.
1313
*/
1414
string getKind();
1515

1616
/**
17-
* Gets a captured model, if any.
17+
* Gets a captured model for `c`, if any.
1818
*/
19-
string getCapturedModel();
19+
string getCapturedModel(Callable c);
2020
}
2121

2222
private module InlineMadTestImpl<InlineMadTestLangSig Lang, InlineMadTestConfigSig Input> {
23-
private string expects() {
24-
Lang::getComment().regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
23+
private string expects(Callable c) {
24+
Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
2525
}
2626

2727
query predicate unexpectedModel(string msg) {
28-
exists(string flow |
29-
flow = Input::getCapturedModel() and
30-
not flow = expects() and
28+
exists(Callable c, string flow |
29+
flow = Input::getCapturedModel(c) and
30+
not flow = expects(c) and
3131
msg = "Unexpected " + Input::getKind() + " found: " + flow
3232
)
3333
}
3434

3535
query predicate expectedModel(string msg) {
36-
exists(string e |
37-
e = expects() and
38-
not e = Input::getCapturedModel() and
36+
exists(Callable c, string e |
37+
e = expects(c) and
38+
not e = Input::getCapturedModel(c) and
3939
msg = "Expected " + Input::getKind() + " missing: " + e
4040
)
4141
}
4242
}
4343

4444
private module InlineMadTestLang implements InlineMadTestLangSig {
45-
string getComment() { result = any(Javadoc doc).getChild(0).toString() }
45+
string getComment(Callable c) {
46+
exists(Javadoc doc |
47+
hasJavadoc(c, doc) and
48+
isNormalComment(doc) and
49+
result = doc.getChild(0).toString()
50+
)
51+
}
4652
}
4753

4854
module InlineMadTest<InlineMadTestConfigSig Input> {

java/ql/test/utils/modelgenerator/dataflow/CaptureNeutralModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import utils.modelgenerator.internal.CaptureSummaryFlowQuery
33
import TestUtilities.InlineMadTest
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getCapturedModel() { result = captureNoFlow(_) }
6+
string getCapturedModel(Callable c) { result = captureNoFlow(c) }
77

88
string getKind() { result = "neutral" }
99
}

java/ql/test/utils/modelgenerator/dataflow/CaptureSinkModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import utils.modelgenerator.internal.CaptureModels
33
import TestUtilities.InlineMadTest
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getCapturedModel() { result = captureSink(_) }
6+
string getCapturedModel(Callable c) { result = captureSink(c) }
77

88
string getKind() { result = "sink" }
99
}

java/ql/test/utils/modelgenerator/dataflow/CaptureSourceModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import utils.modelgenerator.internal.CaptureModels
33
import TestUtilities.InlineMadTest
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getCapturedModel() { result = captureSource(_) }
6+
string getCapturedModel(Callable c) { result = captureSource(c) }
77

88
string getKind() { result = "source" }
99
}

java/ql/test/utils/modelgenerator/dataflow/CaptureSummaryModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import utils.modelgenerator.internal.CaptureSummaryFlowQuery
33
import TestUtilities.InlineMadTest
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getCapturedModel() { result = captureFlow(_) }
6+
string getCapturedModel(Callable c) { result = captureFlow(c) }
77

88
string getKind() { result = "summary" }
99
}

java/ql/test/utils/modelgenerator/dataflow/p/MultipleImpl2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class MultipleImpl2 {
66
// This is used to test that we only generate a summary model and
77
// not neutral summary model for `IInterface.m`.
88
public interface IInterface {
9-
// summary=p;MultipleImpl2$IInterface;true;m;(Object);;Argument[0];ReturnValue;taint;df-generated
109
Object m(Object value);
1110
}
1211

@@ -17,6 +16,7 @@ public Object m(Object value) {
1716
}
1817

1918
public class Impl2 implements IInterface {
19+
// summary=p;MultipleImpl2$IInterface;true;m;(Object);;Argument[0];ReturnValue;taint;df-generated
2020
public Object m(Object value) {
2121
return value;
2222
}

java/ql/test/utils/modelgenerator/dataflow/p/MultipleImpls.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
public class MultipleImpls {
66

77
public static interface Strategy {
8-
// summary=p;MultipleImpls$Strategy;true;doSomething;(String);;Argument[0];Argument[this];taint;df-generated
9-
// summary=p;MultipleImpls$Strategy;true;doSomething;(String);;Argument[0];ReturnValue;taint;df-generated
108
String doSomething(String value);
119
}
1210

1311
public static class Strat1 implements Strategy {
12+
// summary=p;MultipleImpls$Strategy;true;doSomething;(String);;Argument[0];ReturnValue;taint;df-generated
1413
public String doSomething(String value) {
1514
return value;
1615
}
@@ -28,6 +27,7 @@ public String call() throws Exception {
2827
public static class Strat2 implements Strategy {
2928
private String foo;
3029

30+
// summary=p;MultipleImpls$Strategy;true;doSomething;(String);;Argument[0];Argument[this];taint;df-generated
3131
public String doSomething(String value) {
3232
this.foo = value;
3333
return "none";

java/ql/test/utils/modelgenerator/dataflow/p/PrivateFlowViaPublicInterface.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ static class RandomPojo {
1212
}
1313

1414
public static interface SPI {
15-
// summary=p;PrivateFlowViaPublicInterface$SPI;true;openStream;();;Argument[this];ReturnValue;taint;df-generated
16-
// sink=p;PrivateFlowViaPublicInterface$SPI;true;openStream;();;Argument[this];path-injection;df-generated
1715
OutputStream openStream() throws IOException;
1816

1917
// neutral=p;PrivateFlowViaPublicInterface$SPI;openStreamNone;();summary;df-generated
2018
default OutputStream openStreamNone() throws IOException {
2119
return null;
2220
}
23-
;
2421
}
2522

2623
private static final class PrivateImplWithSink implements SPI {
@@ -31,6 +28,8 @@ public PrivateImplWithSink(File file) {
3128
this.file = file;
3229
}
3330

31+
// summary=p;PrivateFlowViaPublicInterface$SPI;true;openStream;();;Argument[this];ReturnValue;taint;df-generated
32+
// sink=p;PrivateFlowViaPublicInterface$SPI;true;openStream;();;Argument[this];path-injection;df-generated
3433
@Override
3534
public OutputStream openStream() throws IOException {
3635
return new FileOutputStream(file);
@@ -46,6 +45,7 @@ public OutputStream openStream() throws IOException {
4645
return null;
4746
}
4847

48+
// neutral=p;PrivateFlowViaPublicInterface$SPI;openStreamNone;();summary;df-generated
4949
@Override
5050
public OutputStream openStreamNone() throws IOException {
5151
return new FileOutputStream(new RandomPojo().someFile);

java/ql/test/utils/modelgenerator/typebasedflow/CaptureTypeBasedSummaryModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TestUtilities.InlineMadTest
33
import utils.modelgenerator.internal.CaptureTypeBasedSummaryModels
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getCapturedModel() { result = captureFlow(_) }
6+
string getCapturedModel(Callable c) { result = captureFlow(c) }
77

88
string getKind() { result = "summary" }
99
}

0 commit comments

Comments
 (0)