mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
Add OS Checks based upon separator or path separator
This commit is contained in:
@@ -202,6 +202,21 @@ class TypeFile extends Class {
|
||||
TypeFile() { this.hasQualifiedName("java.io", "File") }
|
||||
}
|
||||
|
||||
/** The field `java.io.File.separator` or `java.io.File.separatorChar` */
|
||||
class FieldFileSeparator extends Field {
|
||||
FieldFileSeparator() {
|
||||
this.getDeclaringType() instanceof TypeFile and this.hasName(["separator", "separatorChar"])
|
||||
}
|
||||
}
|
||||
|
||||
/* The field `java.io.File.pathSeparator` or `java.io.File.pathSeparatorChar` */
|
||||
class FieldFilePathSeparator extends Field {
|
||||
FieldFilePathSeparator() {
|
||||
this.getDeclaringType() instanceof TypeFile and
|
||||
this.hasName(["pathSeparator", "pathSeparatorChar"])
|
||||
}
|
||||
}
|
||||
|
||||
// --- Standard methods ---
|
||||
/**
|
||||
* Any constructor of class `java.lang.ProcessBuilder`.
|
||||
|
||||
@@ -325,13 +325,10 @@ private predicate formatStringValue(Expr e, string fmtvalue) {
|
||||
or
|
||||
exists(Field f |
|
||||
e = f.getAnAccess() and
|
||||
f.getDeclaringType() instanceof TypeFile and
|
||||
fmtvalue = "x" // dummy value
|
||||
|
|
||||
f.hasName("pathSeparator") or
|
||||
f.hasName("pathSeparatorChar") or
|
||||
f.hasName("separator") or
|
||||
f.hasName("separatorChar")
|
||||
f instanceof FieldFileSeparator or
|
||||
f instanceof FieldFilePathSeperator
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,6 +67,42 @@ private class IsWindowsFromSystemProp extends IsWindowsGuard instanceof MethodAc
|
||||
IsWindowsFromSystemProp() { isOsFromSystemProp(this, "window%") }
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds when the Guard is an equality check between the Field `f` and the string or char constant `compareToLiteral`.
|
||||
*/
|
||||
private Guard isOsFromFieldEqualityCheck(Field f, string compareToLiteral) {
|
||||
result
|
||||
.isEquality(any(FieldAccess fa | fa.getField() = f),
|
||||
any(Literal literal |
|
||||
(literal instanceof CharacterLiteral or literal instanceof StringLiteral) and
|
||||
literal.getValue() = compareToLiteral
|
||||
), _)
|
||||
}
|
||||
|
||||
private class IsWindowsFromCharPathSeperator extends IsWindowsGuard {
|
||||
IsWindowsFromCharPathSeperator() {
|
||||
this = isOsFromFieldEqualityCheck(any(FieldFilePathSeparator f), ";")
|
||||
}
|
||||
}
|
||||
|
||||
private class IsWindowsFromCharSeperator extends IsWindowsGuard {
|
||||
IsWindowsFromCharSeperator() {
|
||||
this = isOsFromFieldEqualityCheck(any(FieldFileSeparator f), "\\")
|
||||
}
|
||||
}
|
||||
|
||||
private class IsUnixFromCharPathSeperator extends IsUnixGuard {
|
||||
IsUnixFromCharPathSeperator() {
|
||||
this = isOsFromFieldEqualityCheck(any(FieldFilePathSeparator f), ":")
|
||||
}
|
||||
}
|
||||
|
||||
private class IsUnixFromCharSeperator extends IsUnixGuard {
|
||||
IsUnixFromCharSeperator() {
|
||||
this = isOsFromFieldEqualityCheck(any(FieldFileSeparator f), "/")
|
||||
}
|
||||
}
|
||||
|
||||
private class IsUnixFromSystemProp extends IsAnyUnixGuard instanceof MethodAccess {
|
||||
IsUnixFromSystemProp() { isOsFromSystemProp(this, ["mac%", "linux%"]) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user