Skip to content

Commit 6007827

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: update test cases
1 parent de59655 commit 6007827

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

java/ql/lib/ext/java.lang.model.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ extensions:
103103
- ["java.lang", "StringBuffer", True, "StringBuffer", "(String)", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
104104
- ["java.lang", "StringBuilder", True, "StringBuilder", "", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
105105
- ["java.lang", "System", False, "arraycopy", "", "", "Argument[0]", "Argument[2]", "taint", "manual"]
106-
- ["java.lang", "System", False, "getProperty", "(String)", "", "Argument[-1].MapValue", "ReturnValue", "value", "manual"]
107106
- ["java.lang", "Throwable", False, "Throwable", "(Throwable)", "", "Argument[0]", "Argument[-1].SyntheticField[java.lang.Throwable.cause]", "value", "manual"]
108107
- ["java.lang", "Throwable", True, "getCause", "()", "", "Argument[-1].SyntheticField[java.lang.Throwable.cause]", "ReturnValue", "value", "manual"]
109108
- ["java.lang", "Throwable", True, "getMessage", "()", "", "Argument[-1].SyntheticField[java.lang.Throwable.message]", "ReturnValue", "value", "manual"]
@@ -137,6 +136,7 @@ extensions:
137136
- ["java.lang", "String", "length", "()", "manual"]
138137
- ["java.lang", "String", "startsWith", "(String)", "manual"]
139138
- ["java.lang", "System", "currentTimeMillis", "()", "manual"]
139+
- ["java.lang", "System", "getProperty", "(String)", "manual"]
140140
- ["java.lang", "System", "nanoTime", "()", "manual"]
141141
- ["java.lang", "Thread", "currentThread", "()", "manual"]
142142
- ["java.lang", "Thread", "sleep", "(long)", "manual"]

java/ql/lib/ext/java.sql.model.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extensions:
1919
pack: codeql/java-all
2020
extensible: summaryModel
2121
data:
22-
- ["java.sql", "PreparedStatement", True, "setInt", "(int,int)", "", "Argument[1]", "Argument[-1].Parameter[Argument[0]]", "value", "manual"] # ! fix output
23-
- ["java.sql", "PreparedStatement", True, "setString", "(int,String)", "", "Argument[1]", "Argument[-1].Parameter[Argument[0]]", "value", "manual"] # ! fix output
22+
- ["java.sql", "PreparedStatement", True, "setInt", "(int,int)", "", "Argument[1]", "Argument[-1]", "value", "manual"]
23+
- ["java.sql", "PreparedStatement", True, "setString", "(int,String)", "", "Argument[1]", "Argument[-1]", "value", "manual"]
2424
- ["java.sql", "ResultSet", True, "getInt", "(String)", "", "Argument[-1]", "ReturnValue", "taint", "manual"]
2525
- ["java.sql", "ResultSet", True, "getString", "(String)", "", "Argument[-1]", "ReturnValue", "taint", "manual"]
2626

java/ql/lib/ext/java.util.concurrent.atomic.model.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ extensions:
33
pack: codeql/java-all
44
extensible: summaryModel
55
data:
6+
- ["java.util.concurrent.atomic", "AtomicInteger", False, "AtomicInteger", "(int)", "", "Argument[0]", "Argument[-1].SyntheticField[java.util.concurrent.atomic.AtomicInteger.value]", "value", "manual"]
67
- ["java.util.concurrent.atomic", "AtomicInteger", False, "get", "()", "", "Argument[-1].SyntheticField[java.util.concurrent.atomic.AtomicInteger.value]", "ReturnValue", "value", "manual"]
8+
- ["java.util.concurrent.atomic", "AtomicReference", False, "AtomicReference", "(Object)", "", "Argument[0]", "Argument[-1].SyntheticField[java.util.concurrent.atomic.AtomicReference.value]", "value", "manual"]
79
- ["java.util.concurrent.atomic", "AtomicReference", False, "get", "()", "", "Argument[-1].SyntheticField[java.util.concurrent.atomic.AtomicReference.value]", "ReturnValue", "value", "manual"]

java/ql/lib/ext/java.util.model.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ extensions:
335335
- ["java.util", "Stack", True, "peek", "()", "", "Argument[-1].Element", "ReturnValue", "value", "manual"]
336336
- ["java.util", "Stack", True, "pop", "()", "", "Argument[-1].Element", "ReturnValue", "value", "manual"]
337337
- ["java.util", "Stack", True, "push", "(Object)", "", "Argument[0]", "Argument[-1].Element", "value", "manual"]
338-
- ["java.util", "StringJoiner", False, "add", "(CharSequence)", "", "Argument[0]", "Argument[-1].Element", "value", "manual"]
338+
- ["java.util", "StringJoiner", False, "add", "(CharSequence)", "", "Argument[-1]", "ReturnValue", "taint", "manual"]
339+
- ["java.util", "StringJoiner", False, "add", "(CharSequence)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
339340
- ["java.util", "StringTokenizer", False, "StringTokenizer", "", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
340341
- ["java.util", "StringTokenizer", False, "nextElement", "()", "", "Argument[-1]", "ReturnValue", "taint", "manual"]
341342
- ["java.util", "StringTokenizer", False, "nextToken", "", "", "Argument[-1]", "ReturnValue", "taint", "manual"]

java/ql/test/ext/TestModels/Test.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ public void test() throws Exception {
9292
long l3 = (long)source();
9393
sink(String.valueOf(l3)); // $hasTaintFlow
9494

95-
// System sys = (System)source();
96-
// sink(sys.getProperty("")); // $hasValueFlow
97-
9895
// java.math
9996
long l4 = (long)source();
10097
sink(BigDecimal.valueOf(l4)); // $hasTaintFlow
@@ -107,36 +104,44 @@ public void test() throws Exception {
107104
sink(Math.min(i4, i5)); // $hasValueFlow
108105

109106
// java.sql
110-
// Connection con = DriverManager.getConnection("");
111-
// PreparedStatement ps = con.prepareStatement("UPDATE EMPLOYEES SET NAME = ? WHERE ID = ?");
112-
// ps.setString(1, "testName"); // $hasValueFlow
113-
// ps.setInt(2, 110592); // $hasValueFlow
107+
Connection con = DriverManager.getConnection("");
108+
PreparedStatement ps1 = con.prepareStatement("UPDATE EMPLOYEES SET NAME = ? WHERE ID = ?");
109+
ps1.setString(1, (String)source());
110+
sink(ps1); // $hasValueFlow
111+
PreparedStatement ps2 = con.prepareStatement("UPDATE EMPLOYEES SET NAME = ? WHERE ID = ?");
112+
ps2.setInt(2, (int)source());
113+
sink(ps2); // $hasValueFlow
114114

115115
ResultSet rs = (ResultSet)source();
116116
sink(rs.getInt("")); // $hasTaintFlow
117117

118118
// java.util.concurrent.atomic
119-
// AtomicInteger ai = new AtomicInteger((int)source());
120-
// sink((int)ai.get()); // $hasValueFlow
119+
AtomicInteger ai = new AtomicInteger((int)source());
120+
sink(ai.get()); // $hasValueFlow
121121

122-
// AtomicReference ar = new AtomicReference(source());
123-
// sink(ar.get()); // $hasValueFlow
122+
AtomicReference ar = new AtomicReference(source());
123+
sink(ar.get()); // $hasValueFlow
124124

125125
// java.util.concurrent
126126
CountDownLatch cdl = new CountDownLatch((int)source());
127127
sink(cdl.getCount()); // $hasValueFlow
128128

129129
// java.util.function
130-
// Function<Object, Object> func = a -> a + "";
131-
// sink(func.apply(source())); // $hasTaintFlow
130+
Function<Object, Object> func = a -> a + "";
131+
sink(func.apply(source())); // $hasTaintFlow
132+
133+
Function<Integer, Double> half = a -> a / 2.0;
134+
sink(half.apply((Integer)source())); // $hasTaintFlow
132135

133136
Supplier<Double> sup = (Supplier)source();
134137
sink(sup.get()); // $hasValueFlow
135138

136139
// java.util
137-
// StringJoiner sj = new StringJoiner(",");
138-
// sink(sj.add((CharSequence)source())); // $hasTaintFlow
139-
}
140+
StringJoiner sj1 = new StringJoiner(",");
141+
sink(sj1.add((CharSequence)source())); // $hasTaintFlow
140142

143+
StringJoiner sj2 = (StringJoiner)source();
144+
sink(sj2.add("test")); // $hasTaintFlow
145+
}
141146
}
142147
}

0 commit comments

Comments
 (0)