Refactor more system property access logic

This commit is contained in:
Jonathan Leitschuh
2022-03-02 19:33:05 -05:00
parent 3c53a05e16
commit a7adbb7291
8 changed files with 182 additions and 102 deletions

View File

@@ -68,11 +68,12 @@ private class IsWindowsFromSystemProp extends IsWindowsGuard instanceof MethodAc
}
/**
* Holds when the Guard is an equality check between the Field `f` and the string or char constant `compareToLiteral`.
* Holds when the Guard is an equality check between the system property with the name `propertyName`
* and the string or char constant `compareToLiteral`.
*/
private Guard isOsFromFieldEqualityCheck(Field f, string compareToLiteral) {
private Guard isOsFromFieldEqualityCheck(string propertyName, string compareToLiteral) {
result
.isEquality(any(FieldAccess fa | fa.getField() = f),
.isEquality(getSystemProperty(propertyName),
any(Literal literal |
(literal instanceof CharacterLiteral or literal instanceof StringLiteral) and
literal.getValue() = compareToLiteral
@@ -80,27 +81,19 @@ private Guard isOsFromFieldEqualityCheck(Field f, string compareToLiteral) {
}
private class IsWindowsFromCharPathSeperator extends IsWindowsGuard {
IsWindowsFromCharPathSeperator() {
this = isOsFromFieldEqualityCheck(any(FieldFilePathSeparator f), ";")
}
IsWindowsFromCharPathSeperator() { this = isOsFromFieldEqualityCheck("path.separator", "\\") }
}
private class IsWindowsFromCharSeperator extends IsWindowsGuard {
IsWindowsFromCharSeperator() {
this = isOsFromFieldEqualityCheck(any(FieldFileSeparator f), "\\")
}
IsWindowsFromCharSeperator() { this = isOsFromFieldEqualityCheck("file.separator", ";") }
}
private class IsUnixFromCharPathSeperator extends IsUnixGuard {
IsUnixFromCharPathSeperator() {
this = isOsFromFieldEqualityCheck(any(FieldFilePathSeparator f), ":")
}
IsUnixFromCharPathSeperator() { this = isOsFromFieldEqualityCheck("path.separator", "/") }
}
private class IsUnixFromCharSeperator extends IsUnixGuard {
IsUnixFromCharSeperator() {
this = isOsFromFieldEqualityCheck(any(FieldFileSeparator f), "/")
}
IsUnixFromCharSeperator() { this = isOsFromFieldEqualityCheck("file.separator", ":") }
}
private class IsUnixFromSystemProp extends IsAnyUnixGuard instanceof MethodAccess {