mirror of
https://github.com/github/codeql.git
synced 2026-01-08 20:20:34 +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)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ public class Test {
|
||||
onlyOnWindows();
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").toLowerCase().contains("window")) {
|
||||
onlyOnWindows();
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
|
||||
onlyOnWindows();
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1415:5:1415:84 | IS_OS_SOLARIS |
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1427:5:1427:83 | IS_OS_SUN_OS |
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1625:5:1625:80 | IS_OS_ZOS |
|
||||
| Test.java:103:13:103:73 | contains(...) |
|
||||
| Test.java:107:13:107:59 | contains(...) |
|
||||
| Test.java:111:13:111:35 | SystemUtils.IS_OS_LINUX |
|
||||
| Test.java:117:14:117:36 | SystemUtils.IS_OS_LINUX |
|
||||
| Test.java:125:13:125:62 | contains(...) |
|
||||
| Test.java:129:14:129:72 | contains(...) |
|
||||
| Test.java:133:14:133:34 | SystemUtils.IS_OS_MAC |
|
||||
| Test.java:139:14:139:45 | SystemUtils.IS_OS_MAC_OSX_MOJAVE |
|
||||
| Test.java:107:13:107:73 | contains(...) |
|
||||
| Test.java:111:13:111:59 | contains(...) |
|
||||
| Test.java:115:13:115:35 | SystemUtils.IS_OS_LINUX |
|
||||
| Test.java:121:14:121:36 | SystemUtils.IS_OS_LINUX |
|
||||
| Test.java:129:13:129:62 | contains(...) |
|
||||
| Test.java:133:14:133:72 | contains(...) |
|
||||
| Test.java:137:14:137:34 | SystemUtils.IS_OS_MAC |
|
||||
| Test.java:143:14:143:45 | SystemUtils.IS_OS_MAC_OSX_MOJAVE |
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1584:5:1584:86 | IS_OS_WINDOWS_7 |
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1596:5:1596:86 | IS_OS_WINDOWS_8 |
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1608:5:1608:87 | IS_OS_WINDOWS_10 |
|
||||
| Test.java:38:13:38:40 | SystemUtils.IS_OS_WINDOWS_XP |
|
||||
| Test.java:42:13:42:40 | SystemUtils.IS_OS_WINDOWS_XP |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1439:5:1439:81 | IS_OS_UNIX |
|
||||
| Test.java:66:13:66:95 | contains(...) |
|
||||
| Test.java:70:13:70:84 | contains(...) |
|
||||
| Test.java:74:13:74:34 | SystemUtils.IS_OS_UNIX |
|
||||
| Test.java:81:13:81:41 | ... == ... |
|
||||
| Test.java:85:13:85:37 | ... == ... |
|
||||
| Test.java:70:13:70:95 | contains(...) |
|
||||
| Test.java:74:13:74:84 | contains(...) |
|
||||
| Test.java:78:13:78:34 | SystemUtils.IS_OS_UNIX |
|
||||
| Test.java:85:13:85:41 | ... == ... |
|
||||
| Test.java:89:13:89:37 | ... == ... |
|
||||
| Test.java:93:13:93:33 | ... == ... |
|
||||
| Test.java:97:13:97:60 | equals(...) |
|
||||
| Test.java:93:13:93:37 | ... == ... |
|
||||
| Test.java:97:13:97:33 | ... == ... |
|
||||
| Test.java:101:13:101:60 | equals(...) |
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
| ../../stubs/apache-commons-lang3-3.7/org/apache/commons/lang3/SystemUtils.java:1451:5:1451:84 | IS_OS_WINDOWS |
|
||||
| Test.java:20:13:20:61 | contains(...) |
|
||||
| Test.java:24:13:24:75 | contains(...) |
|
||||
| Test.java:28:13:28:75 | contains(...) |
|
||||
| Test.java:32:13:32:37 | SystemUtils.IS_OS_WINDOWS |
|
||||
| Test.java:44:13:44:41 | ... == ... |
|
||||
| Test.java:48:13:48:37 | ... == ... |
|
||||
| Test.java:52:13:52:38 | ... == ... |
|
||||
| Test.java:56:13:56:34 | ... == ... |
|
||||
| Test.java:60:13:60:60 | equals(...) |
|
||||
| Test.java:28:13:28:74 | contains(...) |
|
||||
| Test.java:32:13:32:75 | contains(...) |
|
||||
| Test.java:36:13:36:37 | SystemUtils.IS_OS_WINDOWS |
|
||||
| Test.java:48:13:48:41 | ... == ... |
|
||||
| Test.java:52:13:52:37 | ... == ... |
|
||||
| Test.java:56:13:56:38 | ... == ... |
|
||||
| Test.java:60:13:60:34 | ... == ... |
|
||||
| Test.java:64:13:64:60 | equals(...) |
|
||||
|
||||
Reference in New Issue
Block a user