Skip to content

Commit 1185e28

Browse files
committed
Java: Add some spurious source and sink model generation examples.
1 parent ed3f1e4 commit 1185e28

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
3+
- addsTo:
4+
pack: codeql/java-all
5+
extensible: sourceModel
6+
data:
7+
- [ "p", "Sources", False, "source", "()", "", "ReturnValue", "test-source", "manual" ]

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@ public void hasManualSinkNeutral(Object o) {
6464
public void compoundPropgate(Sinks s) {
6565
s.fieldSink();
6666
}
67+
68+
// Not a new sink because a simple type is used in an intermediate step
69+
// SPURIOUS-sink=p;Sinks;true;wrapSinkSimpleType;(String);;Argument[0];test-sink;df-generated
70+
// neutral=p;Sinks;wrapSinkSimpleType;(String);summary;df-generated
71+
public void wrapSinkSimpleType(String s) {
72+
Boolean b = s == "hello";
73+
sink(b);
74+
}
6775
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
public class Sources {
1010

11+
// Defined as a source in the model file next to the test.
12+
// neutral=p;Sources;source;();summary;df-generated
13+
public String source() {
14+
return "";
15+
}
16+
1117
// source=p;Sources;true;readUrl;(URL);;ReturnValue;remote;df-generated
1218
// sink=p;Sources;true;readUrl;(URL);;Argument[0];request-forgery;df-generated
1319
// neutral=p;Sources;readUrl;(URL);summary;df-generated
@@ -37,4 +43,28 @@ public void sourceToParameter(InputStream[] streams, List<InputStream> otherStre
3743
streams[0] = socket.accept().getInputStream();
3844
otherStreams.add(socket.accept().getInputStream());
3945
}
46+
47+
// Not a new source because a simple type is used in an intermediate step
48+
// SPURIOUS-source=p;Sources;true;wrapSourceGetBool;();;ReturnValue;test-source;df-generated
49+
// neutral=p;Sources;wrapSourceGetBool;();summary;df-generated
50+
public Boolean wrapSourceGetBool() {
51+
String s = source();
52+
return s == "hello";
53+
}
54+
55+
public class SourceReader {
56+
@Override
57+
public String toString() {
58+
return source();
59+
}
60+
}
61+
62+
public class MyContainer<T> {
63+
private T value;
64+
65+
// neutral=p;Sources$MyContainer;read;();summary;df-generated
66+
public String read() {
67+
return value.toString();
68+
}
69+
}
4070
}

0 commit comments

Comments
 (0)