mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Add MethodAccessSystemGetProperty predicate
This commit is contained in:
@@ -211,6 +211,21 @@ class MethodSystemGetProperty extends Method {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Any method access to a method named `getProperty` on class `java.lang.System`.
|
||||
*/
|
||||
class MethodAccessSystemGetProperty extends MethodAccess {
|
||||
MethodAccessSystemGetProperty() { getMethod() instanceof MethodSystemGetProperty }
|
||||
|
||||
/**
|
||||
* Holds true if this is a compile-time constant call for the specified `propertyName`.
|
||||
* Eg. `System.getProperty("user.dir")`.
|
||||
*/
|
||||
predicate hasCompileTimeConstantGetPropertyName(string propertyName) {
|
||||
this.getArgument(0).(CompileTimeConstantExpr).getStringValue() = propertyName
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Any method named `exit` on class `java.lang.Runtime` or `java.lang.System`.
|
||||
*/
|
||||
|
||||
@@ -16,5 +16,6 @@ class PrintAstConfigurationOverride extends PrintAstConfiguration {
|
||||
/**
|
||||
* TWEAK THIS PREDICATE AS NEEDED.
|
||||
*/
|
||||
override predicate shouldPrint(Element e, Location l) { super.shouldPrint(e, l) }
|
||||
override predicate shouldPrint(Element e, Location l) { super.shouldPrint(e, l) and
|
||||
not l.getFile().getBaseName().matches("SystemGetPropertyCall.java") }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
| jdk/SystemGetPropertyCall.java:7:9:7:38 | getProperty(...) |
|
||||
| jdk/SystemGetPropertyCall.java:11:9:11:46 | getProperty(...) |
|
||||
| jdk/SystemGetPropertyCall.java:15:9:15:45 | getProperty(...) |
|
||||
10
java/ql/test/library-tests/JDK/SystemGetPropertyCall.ql
Normal file
10
java/ql/test/library-tests/JDK/SystemGetPropertyCall.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @name SystemCall
|
||||
* @description Test the definition of System Get Property
|
||||
*/
|
||||
|
||||
import default
|
||||
|
||||
from MethodAccessSystemGetProperty ma
|
||||
where ma.hasCompileTimeConstantGetPropertyName("user.dir")
|
||||
select ma
|
||||
@@ -0,0 +1,21 @@
|
||||
package jdk;
|
||||
|
||||
public class SystemGetPropertyCall {
|
||||
private static final String USER_DIR_PROPERTY = "user.dir";
|
||||
|
||||
void a() {
|
||||
System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
void b() {
|
||||
System.getProperty("user.dir", "HOME");
|
||||
}
|
||||
|
||||
void c() {
|
||||
System.getProperty(USER_DIR_PROPERTY);
|
||||
}
|
||||
|
||||
void d() {
|
||||
System.getProperty("random.property");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user