Skip to content

Commit b282c7f

Browse files
JLLeitschuhMarcono1234smowton
authored
Apply suggestions from code review
Co-authored-by: Marcono1234 <[email protected]> Co-authored-by: Chris Smowton <[email protected]>
1 parent 523ddb7 commit b282c7f

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

java/ql/lib/semmle/code/java/environment/SystemProperty.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Expr getSystemProperty(string propertyName) {
2020
private MethodAccess getSystemPropertyFromSystem(string propertyName) {
2121
result.(MethodAccessSystemGetProperty).hasCompileTimeConstantGetPropertyName(propertyName)
2222
or
23-
exists(Method m | result.getMethod() = m | m.hasName("lineSeparator")) and
23+
result.getMethod().hasName("lineSeparator") and
2424
propertyName = "line.separator"
2525
}
2626

java/ql/lib/semmle/code/java/os/OSCheck.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ private import semmle.code.java.dataflow.DataFlow
1010
private import semmle.code.java.dataflow.TaintTracking
1111

1212
/**
13-
* A guard that checks if the current os is Windows.
13+
* A guard that checks if the current OS is Windows.
1414
* When True, the OS is Windows.
1515
* When False, the OS is not Windows.
1616
*/
1717
abstract class IsWindowsGuard extends Guard { }
1818

1919
/**
20-
* A guard that checks if the current OS is any Windows.
20+
* A guard that checks if the current OS is a specific Windows variant.
2121
* When True, the OS is Windows.
2222
* When False, the OS *may* still be Windows.
2323
*/
@@ -31,7 +31,7 @@ abstract class IsSpecificWindowsVariant extends Guard { }
3131
abstract class IsUnixGuard extends Guard { }
3232

3333
/**
34-
* A guard that checks if the current OS is unix or unix-like.
34+
* A guard that checks if the current OS is a specific unix or unix-like variant.
3535
* When True, the OS is unix or unix-like.
3636
* When False, the OS *may* still be unix or unix-like.
3737
*/
@@ -42,7 +42,7 @@ abstract class IsSpecificUnixVariant extends Guard { }
4242
*/
4343
bindingset[osString]
4444
private predicate isOsFromSystemProp(MethodAccess ma, string osString) {
45-
TaintTracking::localExprTaint(getSystemProperty("os.name"), ma.getQualifier()) and // Call from System.getProperty (or equvalent) to some partial match method
45+
TaintTracking::localExprTaint(getSystemProperty("os.name"), ma.getQualifier()) and // Call from System.getProperty (or equivalent) to some partial match method
4646
exists(StringPartialMatchMethod m, CompileTimeConstantExpr matchedStringConstant |
4747
m = ma.getMethod() and
4848
matchedStringConstant.getStringValue().toLowerCase().matches(osString)
@@ -68,24 +68,24 @@ private Guard isOsFromSystemPropertyEqualityCheck(string propertyName, string co
6868
), _)
6969
}
7070

71-
private class IsWindowsFromCharPathSeperator extends IsWindowsGuard {
72-
IsWindowsFromCharPathSeperator() {
71+
private class IsWindowsFromCharPathSeparator extends IsWindowsGuard {
72+
IsWindowsFromCharPathSeparator() {
7373
this = isOsFromSystemPropertyEqualityCheck("path.separator", "\\")
7474
}
7575
}
7676

77-
private class IsWindowsFromCharSeperator extends IsWindowsGuard {
78-
IsWindowsFromCharSeperator() { this = isOsFromSystemPropertyEqualityCheck("file.separator", ";") }
77+
private class IsWindowsFromCharSeparator extends IsWindowsGuard {
78+
IsWindowsFromCharSeparator() { this = isOsFromSystemPropertyEqualityCheck("file.separator", ";") }
7979
}
8080

81-
private class IsUnixFromCharPathSeperator extends IsUnixGuard {
82-
IsUnixFromCharPathSeperator() {
81+
private class IsUnixFromCharPathSeparator extends IsUnixGuard {
82+
IsUnixFromCharPathSeparator() {
8383
this = isOsFromSystemPropertyEqualityCheck("path.separator", "/")
8484
}
8585
}
8686

87-
private class IsUnixFromCharSeperator extends IsUnixGuard {
88-
IsUnixFromCharSeperator() { this = isOsFromSystemPropertyEqualityCheck("file.separator", ":") }
87+
private class IsUnixFromCharSeparator extends IsUnixGuard {
88+
IsUnixFromCharSeparator() { this = isOsFromSystemPropertyEqualityCheck("file.separator", ":") }
8989
}
9090

9191
private class IsUnixFromSystemProp extends IsSpecificUnixVariant instanceof MethodAccess {
@@ -138,12 +138,12 @@ private class IsUnixFromPosixFromFileSystem extends IsUnixGuard instanceof Metho
138138
m.hasName("contains")
139139
) and
140140
this.getArgument(0).(CompileTimeConstantExpr).getStringValue() = "posix" and
141-
exists(Method supportedFileAttribtueViewsMethod |
142-
supportedFileAttribtueViewsMethod.hasName("supportedFileAttributeViews") and
143-
supportedFileAttribtueViewsMethod.getDeclaringType() instanceof TypeFileSystem
141+
exists(Method supportedFileAttributeViewsMethod |
142+
supportedFileAttributeViewsMethod.hasName("supportedFileAttributeViews") and
143+
supportedFileAttributeViewsMethod.getDeclaringType() instanceof TypeFileSystem
144144
|
145145
DataFlow::localExprFlow(any(MethodAccess ma |
146-
ma.getMethod() = supportedFileAttribtueViewsMethod
146+
ma.getMethod() = supportedFileAttributeViewsMethod
147147
), super.getQualifier())
148148
)
149149
}

java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private class IsWindowsBarrierGuard extends WindowsOsBarrierGuard instanceof IsW
118118
override predicate checks(Expr e, boolean branch) { this.controls(e.getBasicBlock(), branch) }
119119
}
120120

121-
private class IsAnyWindowsBarrierGuard extends WindowsOsBarrierGuard instanceof IsSpecificWindowsVariant {
121+
private class IsSpecificWindowsBarrierGuard extends WindowsOsBarrierGuard instanceof IsSpecificWindowsVariant {
122122
override predicate checks(Expr e, boolean branch) {
123123
branch = true and this.controls(e.getBasicBlock(), branch)
124124
}

java/ql/src/change-notes/2022-02-14-os-guards.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
category: minorAnalysis
33
---
44
* Add new guards `IsWindowsGuard`, `IsSpecificWindowsVariant`, `IsUnixGuard`, and `IsSpecificUnixVariant` to detect OS specific guards.
5-
* Add new predicate `getSystemProperty` that gets all expressions that retrieve system properties from a variety of sources (eg. alternative JDK API's, Google Guava, Apache Commons, Apache IO, ect..).
5+
* Add new predicate `getSystemProperty` that gets all expressions that retrieve system properties from a variety of sources (eg. alternative JDK API's, Google Guava, Apache Commons, Apache IO, etc..).
66
* Update "Local information disclosure in a temporary directory" (`java/local-temp-file-or-directory-information-disclosure`) to remove false-positives when OS is properly used as logical guard.
7-
* Update "Local information disclosure in a temporary directory" (`java/local-temp-file-or-directory-information-disclosure`) to use `getSystemProperty` to use new `getSystemProperty` predicate.
7+
* Update "Local information disclosure in a temporary directory" (`java/local-temp-file-or-directory-information-disclosure`) to use new `getSystemProperty` predicate.
88

0 commit comments

Comments
 (0)