Minor refactoring to improve tests and documentation

This commit is contained in:
Jonathan Leitschuh
2022-03-07 18:40:53 -05:00
parent 5b651f29d8
commit a21992ade9
8 changed files with 37 additions and 31 deletions

View File

@@ -70,7 +70,7 @@ private class FieldFilePathSeparator extends Field {
* See: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/SystemUtils.html
*/
private FieldAccess getSystemPropertyFromApacheSystemUtils(string propertyName) {
exists(Field f | f = result.getField() and f.getDeclaringType() instanceof ApacheSystemUtils |
exists(Field f | f = result.getField() and f.getDeclaringType() instanceof TypeApacheSystemUtils |
f.hasName("AWT_TOOLKIT") and propertyName = "awt.toolkit"
or
f.hasName("FILE_ENCODING") and propertyName = "file.encoding"

View File

@@ -41,8 +41,8 @@ private class ApacheStrBuilderFluentMethod extends FluentMethod {
/**
* The class `org.apache.commons.lang.SystemUtils` or `org.apache.commons.lang3.SystemUtils`.
*/
class ApacheSystemUtils extends Class {
ApacheSystemUtils() {
class TypeApacheSystemUtils extends Class {
TypeApacheSystemUtils() {
this.hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"], "SystemUtils")
}
}

View File

@@ -40,19 +40,18 @@ abstract class IsSpecificUnixVariant extends Guard { }
/**
* Holds when `ma` compares the current OS against the string constant `osString`.
*/
bindingset[osString]
private predicate isOsFromSystemProp(MethodAccess ma, string osString) {
TaintTracking::localExprTaint(getSystemProperty("os.name"), ma.getQualifier()) and // Call from System.getProperty (or equivalent) to some partial match method
exists(StringPartialMatchMethod m, CompileTimeConstantExpr matchedStringConstant |
m = ma.getMethod() and
matchedStringConstant.getStringValue().toLowerCase().matches(osString)
matchedStringConstant.getStringValue().toLowerCase() = osString
|
DataFlow::localExprFlow(matchedStringConstant, ma.getArgument(m.getMatchParameterIndex()))
)
}
private class IsWindowsFromSystemProp extends IsWindowsGuard instanceof MethodAccess {
IsWindowsFromSystemProp() { isOsFromSystemProp(this, "window%") }
IsWindowsFromSystemProp() { isOsFromSystemProp(this, any(string s | s.regexpMatch("windows?"))) }
}
/**
@@ -99,13 +98,15 @@ private class IsUnixFromCharSeparator extends IsUnixGuard {
}
private class IsUnixFromSystemProp extends IsSpecificUnixVariant instanceof MethodAccess {
IsUnixFromSystemProp() { isOsFromSystemProp(this, ["mac%", "linux%"]) }
IsUnixFromSystemProp() {
isOsFromSystemProp(this, any(string s | s.regexpMatch(["mac.*", "linux.*"])))
}
}
bindingset[fieldNamePattern]
private predicate isOsFromApacheCommons(FieldAccess fa, string fieldNamePattern) {
exists(Field f | f = fa.getField() |
f.getDeclaringType() instanceof ApacheSystemUtils and
f.getDeclaringType() instanceof TypeApacheSystemUtils and
f.getName().matches(fieldNamePattern)
)
}