Skip to content

Commit 09cc8ee

Browse files
committed
Add tests for StandardSystemProperty
1 parent 451661d commit 09cc8ee

File tree

5 files changed

+166
-15
lines changed

5 files changed

+166
-15
lines changed

java/ql/lib/semmle/code/java/environment/SystemProperty.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,18 @@ private MethodAccess getSystemPropertyFromApacheFileUtils(string propertyName) {
170170
private MethodAccess getSystemPropertyFromGuava(string propertyName) {
171171
exists(EnumConstant ec |
172172
ec.getDeclaringType().hasQualifiedName("com.google.common.base", "StandardSystemProperty") and
173-
result.getQualifier() = ec.getAnAccess() and
174-
result.getMethod().hasName("value")
173+
// Example: `StandardSystemProperty.JAVA_IO_TMPDIR.value()`
174+
(
175+
localExprFlowPlusInitializers(ec.getAnAccess(), result.getQualifier()) and
176+
result.getMethod().hasName("value")
177+
)
178+
or
179+
// Example: `System.getProperty(StandardSystemProperty.JAVA_IO_TMPDIR.key())`
180+
exists(MethodAccess keyMa |
181+
localExprFlowPlusInitializers(ec.getAnAccess(), keyMa.getQualifier()) and
182+
keyMa.getMethod().hasName("key") and
183+
localExprFlowPlusInitializers(keyMa, result.(MethodAccessSystemGetProperty).getArgument(0))
184+
)
175185
|
176186
ec.hasName("JAVA_VERSION") and propertyName = "java.version"
177187
or

java/ql/test/library-tests/environment/SystemPropertyAccess.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java.io.File;
22
import java.util.Properties;
33
import org.apache.commons.lang3.SystemUtils;
4+
import com.google.common.base.StandardSystemProperty;
45

56
public class SystemPropertyAccess {
67
private static final Properties SYSTEM_PROPERTIES = System.getProperties();
@@ -20,6 +21,10 @@ void test() {
2021
char separatorChar = File.separatorChar;
2122
String pathSeparator = File.pathSeparator;
2223
char pathSeparatorChar = File.pathSeparatorChar;
24+
StandardSystemProperty.JAVA_VERSION.value();
25+
StandardSystemProperty property = StandardSystemProperty.JAVA_VERSION;
26+
property.value();
27+
System.getProperty(StandardSystemProperty.JAVA_IO_TMPDIR.key());
2328
}
2429

2530
}

java/ql/test/library-tests/environment/SystemPropertyTest.expected

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@
3838
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:843:5:843:48 | USER_NAME | user.name |
3939
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:861:5:861:52 | USER_TIMEZONE | user.timezone |
4040
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1762:47:1762:63 | JAVA_AWT_HEADLESS | java.awt.headless |
41-
| SystemPropertyAccess.java:9:9:9:37 | getProperty(...) | os.name |
42-
| SystemPropertyAccess.java:10:9:10:48 | getProperty(...) | os.name |
43-
| SystemPropertyAccess.java:11:9:11:53 | getProperty(...) | os.name |
44-
| SystemPropertyAccess.java:12:9:12:52 | get(...) | java.io.tmpdir |
45-
| SystemPropertyAccess.java:15:9:15:30 | lineSeparator(...) | line.separator |
46-
| SystemPropertyAccess.java:16:29:16:51 | SystemUtils.AWT_TOOLKIT | awt.toolkit |
47-
| SystemPropertyAccess.java:17:31:17:55 | SystemUtils.FILE_ENCODING | file.encoding |
48-
| SystemPropertyAccess.java:18:25:18:50 | SystemUtils.JAVA_IO_TMPDIR | java.io.tmpdir |
49-
| SystemPropertyAccess.java:19:28:19:41 | File.separator | file.separator |
50-
| SystemPropertyAccess.java:20:30:20:47 | File.separatorChar | file.separator |
51-
| SystemPropertyAccess.java:21:32:21:49 | File.pathSeparator | path.separator |
52-
| SystemPropertyAccess.java:22:34:22:55 | File.pathSeparatorChar | path.separator |
41+
| SystemPropertyAccess.java:10:9:10:37 | getProperty(...) | os.name |
42+
| SystemPropertyAccess.java:11:9:11:48 | getProperty(...) | os.name |
43+
| SystemPropertyAccess.java:12:9:12:53 | getProperty(...) | os.name |
44+
| SystemPropertyAccess.java:13:9:13:52 | get(...) | java.io.tmpdir |
45+
| SystemPropertyAccess.java:14:9:14:50 | getProperty(...) | java.home |
46+
| SystemPropertyAccess.java:15:9:15:46 | get(...) | file.encoding |
47+
| SystemPropertyAccess.java:16:9:16:30 | lineSeparator(...) | line.separator |
48+
| SystemPropertyAccess.java:17:29:17:51 | SystemUtils.AWT_TOOLKIT | awt.toolkit |
49+
| SystemPropertyAccess.java:18:31:18:55 | SystemUtils.FILE_ENCODING | file.encoding |
50+
| SystemPropertyAccess.java:19:25:19:50 | SystemUtils.JAVA_IO_TMPDIR | java.io.tmpdir |
51+
| SystemPropertyAccess.java:20:28:20:41 | File.separator | file.separator |
52+
| SystemPropertyAccess.java:21:30:21:47 | File.separatorChar | file.separator |
53+
| SystemPropertyAccess.java:22:32:22:49 | File.pathSeparator | path.separator |
54+
| SystemPropertyAccess.java:23:34:23:55 | File.pathSeparatorChar | path.separator |
55+
| SystemPropertyAccess.java:24:9:24:51 | value(...) | java.version |
56+
| SystemPropertyAccess.java:26:9:26:24 | value(...) | java.version |
57+
| SystemPropertyAccess.java:27:9:27:71 | getProperty(...) | java.io.tmpdir |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//semmle-extractor-options: --javac-args -cp ${testdir}/../../stubs/apache-commons-lang3-3.7/
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../stubs/apache-commons-lang3-3.7/:${testdir}/../../stubs/guava-30.0/

java/ql/test/stubs/guava-30.0/com/google/common/base/StandardSystemProperty.java

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)