mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Fix query java/internal-representation-exposure regarding generic callees, and add a test
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
| ExposesRep.java:11:19:11:28 | getStrings | getStrings exposes the internal representation stored in field strings. The value may be modified $@. | User.java:5:5:5:19 | User.java:5:5:5:19 | after this call to getStrings |
|
||||
| ExposesRep.java:11:19:11:28 | getStrings | getStrings exposes the internal representation stored in field strings. The value may be modified $@. | User.java:13:12:13:26 | User.java:13:12:13:26 | after this call to getStrings |
|
||||
| ExposesRep.java:11:19:11:28 | getStrings | getStrings exposes the internal representation stored in field strings. The value may be modified $@. | User.java:38:12:38:26 | User.java:38:12:38:26 | after this call to getStrings |
|
||||
| ExposesRep.java:13:30:13:41 | getStringMap | getStringMap exposes the internal representation stored in field stringMap. The value may be modified $@. | User.java:9:5:9:21 | User.java:9:5:9:21 | after this call to getStringMap |
|
||||
| ExposesRep.java:17:15:17:24 | setStrings | setStrings exposes the internal representation stored in field strings. The value may be modified $@. | User.java:22:5:22:6 | User.java:22:5:22:6 | through the variable ss |
|
||||
| ExposesRep.java:21:15:21:26 | setStringMap | setStringMap exposes the internal representation stored in field stringMap. The value may be modified $@. | User.java:27:5:27:5 | User.java:27:5:27:5 | through the variable m |
|
||||
| ExposesRep.java:29:14:29:21 | getArray | getArray exposes the internal representation stored in field array. The value may be modified $@. | User.java:31:5:31:18 | User.java:31:5:31:18 | after this call to getArray |
|
||||
@@ -0,0 +1 @@
|
||||
Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql
|
||||
@@ -0,0 +1,30 @@
|
||||
import java.util.Map;
|
||||
|
||||
public class ExposesRep {
|
||||
private String[] strings;
|
||||
private Map<String, String> stringMap;
|
||||
|
||||
public ExposesRep() {
|
||||
strings = new String[1];
|
||||
}
|
||||
|
||||
public String[] getStrings() { return strings; }
|
||||
|
||||
public Map<String, String> getStringMap() {
|
||||
return stringMap;
|
||||
}
|
||||
|
||||
public void setStrings(String[] ss) {
|
||||
this.strings = ss;
|
||||
}
|
||||
|
||||
public void setStringMap(Map<String, String> m) {
|
||||
this.stringMap = m;
|
||||
}
|
||||
}
|
||||
|
||||
class GenericExposesRep<T> {
|
||||
private T[] array;
|
||||
|
||||
public T[] getArray() { return array; }
|
||||
}
|
||||
45
java/ql/test/query-tests/ExposeRepresentation/User.java
Normal file
45
java/ql/test/query-tests/ExposeRepresentation/User.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import java.util.Map;
|
||||
|
||||
public class User {
|
||||
public static void test1(ExposesRep er) {
|
||||
er.getStrings()[0] = "Hello world";
|
||||
}
|
||||
|
||||
public static void test2(ExposesRep er) {
|
||||
er.getStringMap().put("Hello", "world");
|
||||
}
|
||||
|
||||
public String[] indirectGetStrings(ExposesRep er) {
|
||||
return er.getStrings();
|
||||
}
|
||||
|
||||
public void test3(ExposesRep er) {
|
||||
indirectGetStrings(er)[0] = "Hello world";
|
||||
}
|
||||
|
||||
public static void test4(ExposesRep er, String[] ss) {
|
||||
er.setStrings(ss);
|
||||
ss[0] = "Hello world";
|
||||
}
|
||||
|
||||
public static void test5(ExposesRep er, Map<String, String> m) {
|
||||
er.setStringMap(m);
|
||||
m.put("Hello", "world");
|
||||
}
|
||||
|
||||
public static void test6(GenericExposesRep<String> ger) {
|
||||
ger.getArray()[0] = "Hello world";
|
||||
}
|
||||
}
|
||||
|
||||
class GenericUser<T> {
|
||||
|
||||
public String[] indirectGetStrings(ExposesRep er) {
|
||||
return er.getStrings();
|
||||
}
|
||||
|
||||
public static void test1(ExposesRep er, GenericUser<String> gu) {
|
||||
gu.indirectGetStrings(er)[0] = "Hello world";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user