Skip to content

Commit e56c185

Browse files
committed
Java: Add some model generator sink examples.
1 parent 854c6fa commit e56c185

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extensions:
2+
3+
- addsTo:
4+
pack: codeql/java-all
5+
extensible: sinkModel
6+
data:
7+
- [ "p", "Sinks", False, "sink", "(Object)", "", "Argument[0]", "test-sink", "manual" ]
8+
9+
- addsTo:
10+
pack: codeql/java-all
11+
extensible: neutralModel
12+
data:
13+
- [ "p", "Sinks", "hasManualSinkNeutral", "(Object)", "sink", "manual"]

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
public class Sinks {
1313

14+
public Object tainted;
15+
16+
// Defined as a sink in the model file next to the test.
17+
// neutral=p;Sinks;sink;(Object);summary;df-generated
18+
public void sink(Object o) {}
19+
1420
// sink=p;Sinks;true;copyFileToDirectory;(Path,Path,CopyOption[]);;Argument[0];path-injection;df-generated
1521
// sink=p;Sinks;true;copyFileToDirectory;(Path,Path,CopyOption[]);;Argument[1];path-injection;df-generated
1622
// neutral=p;Sinks;copyFileToDirectory;(Path,Path,CopyOption[]);summary;df-generated
@@ -38,4 +44,24 @@ public void propagate(String s) {
3844
Logger logger = Logger.getLogger(Sinks.class.getSimpleName());
3945
logger.warning(s);
4046
}
47+
48+
// New sink as the value of a public field is propagated to a sink.
49+
// sink=p;Sinks;true;fieldSink;();;Argument[this];test-sink;df-generated
50+
// neutral=p;Sinks;fieldSink;();summary;df-generated
51+
public void fieldSink() {
52+
sink(tainted);
53+
}
54+
55+
// Not a new sink as this method is already defined as a manual
56+
// sink neutral.
57+
// neutral=p;Sinks;hasManualSinkNeutral;(Object);summary;df-generated
58+
public void hasManualSinkNeutral(Object o) {
59+
sink(o);
60+
}
61+
62+
// MISSING SINK
63+
// neutral=p;Sinks;compoundPropgate;(Sinks);summary;df-generated
64+
public void compoundPropgate(Sinks s) {
65+
s.fieldSink();
66+
}
4167
}

0 commit comments

Comments
 (0)