mirror of
https://github.com/github/codeql.git
synced 2026-02-02 08:12:58 +01:00
Minor refactoring to improve tests and documentation
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user