@@ -7,6 +7,7 @@ import semmle.code.java.controlflow.Guards
7
7
private import semmle.code.java.environment.SystemProperty
8
8
private import semmle.code.java.frameworks.apache.Lang
9
9
private import semmle.code.java.dataflow.DataFlow
10
+ private import semmle.code.java.dataflow.TaintTracking
10
11
11
12
/**
12
13
* A guard that checks if the current os is Windows.
@@ -20,7 +21,7 @@ abstract class IsWindowsGuard extends Guard { }
20
21
* When True, the OS is Windows.
21
22
* When False, the OS *may* still be Windows.
22
23
*/
23
- abstract class IsAnyWindowsGuard extends Guard { }
24
+ abstract class IsSpecificWindowsVariant extends Guard { }
24
25
25
26
/**
26
27
* A guard that checks if the current OS is unix or unix-like.
@@ -34,33 +35,20 @@ abstract class IsUnixGuard extends Guard { }
34
35
* When True, the OS is unix or unix-like.
35
36
* When False, the OS *may* still be unix or unix-like.
36
37
*/
37
- abstract class IsAnyUnixGuard extends Guard { }
38
+ abstract class IsSpecificUnixVariant extends Guard { }
38
39
39
40
/**
40
41
* Holds when `ma` compares the current OS against the string constant `osString`.
41
42
*/
42
43
bindingset [ osString]
43
44
private predicate isOsFromSystemProp ( MethodAccess ma , string osString ) {
44
- exists ( Expr systemGetPropertyExpr , Expr systemGetPropertyFlowsToExpr |
45
- systemGetPropertyExpr = getSystemProperty ( "os.name" )
45
+ TaintTracking:: localExprTaint ( getSystemProperty ( "os.name" ) , ma .getQualifier ( ) ) and // Call from System.getProperty (or equvalent) to some partial match method
46
+ exists ( StringPartialMatchMethod m , CompileTimeConstantExpr matchedStringConstant |
47
+ m = ma .getMethod ( ) and
48
+ matchedStringConstant .getStringValue ( ) .toLowerCase ( ) .matches ( osString )
46
49
|
47
- DataFlow:: localExprFlow ( systemGetPropertyExpr , systemGetPropertyFlowsToExpr ) and
48
- ma .getAnArgument ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) .toLowerCase ( ) .matches ( osString ) and // Call from System.getProperty to some partial match method
49
- (
50
- systemGetPropertyFlowsToExpr = ma .getQualifier ( )
51
- or
52
- exists ( MethodAccess caseChangeMa |
53
- caseChangeMa .getMethod ( ) =
54
- any ( Method m |
55
- m .getDeclaringType ( ) instanceof TypeString and m .hasName ( [ "toLowerCase" , "toUpperCase" ] )
56
- )
57
- |
58
- systemGetPropertyFlowsToExpr = caseChangeMa .getQualifier ( ) and // Call from System.getProperty to case-switching method
59
- DataFlow:: localExprFlow ( caseChangeMa , ma .getQualifier ( ) ) // Call from case-switching method to some partial match method
60
- )
61
- )
62
- ) and
63
- ma .getMethod ( ) instanceof StringPartialMatchMethod
50
+ DataFlow:: localExprFlow ( matchedStringConstant , ma .getArgument ( m .getMatchParameterIndex ( ) ) )
51
+ )
64
52
}
65
53
66
54
private class IsWindowsFromSystemProp extends IsWindowsGuard instanceof MethodAccess {
@@ -81,22 +69,26 @@ private Guard isOsFromSystemPropertyEqualityCheck(string propertyName, string co
81
69
}
82
70
83
71
private class IsWindowsFromCharPathSeperator extends IsWindowsGuard {
84
- IsWindowsFromCharPathSeperator ( ) { this = isOsFromSystemPropertyEqualityCheck ( "path.separator" , "\\" ) }
72
+ IsWindowsFromCharPathSeperator ( ) {
73
+ this = isOsFromSystemPropertyEqualityCheck ( "path.separator" , "\\" )
74
+ }
85
75
}
86
76
87
77
private class IsWindowsFromCharSeperator extends IsWindowsGuard {
88
78
IsWindowsFromCharSeperator ( ) { this = isOsFromSystemPropertyEqualityCheck ( "file.separator" , ";" ) }
89
79
}
90
80
91
81
private class IsUnixFromCharPathSeperator extends IsUnixGuard {
92
- IsUnixFromCharPathSeperator ( ) { this = isOsFromSystemPropertyEqualityCheck ( "path.separator" , "/" ) }
82
+ IsUnixFromCharPathSeperator ( ) {
83
+ this = isOsFromSystemPropertyEqualityCheck ( "path.separator" , "/" )
84
+ }
93
85
}
94
86
95
87
private class IsUnixFromCharSeperator extends IsUnixGuard {
96
88
IsUnixFromCharSeperator ( ) { this = isOsFromSystemPropertyEqualityCheck ( "file.separator" , ":" ) }
97
89
}
98
90
99
- private class IsUnixFromSystemProp extends IsAnyUnixGuard instanceof MethodAccess {
91
+ private class IsUnixFromSystemProp extends IsSpecificUnixVariant instanceof MethodAccess {
100
92
IsUnixFromSystemProp ( ) { isOsFromSystemProp ( this , [ "mac%" , "linux%" ] ) }
101
93
}
102
94
@@ -112,16 +104,16 @@ private class IsWindowsFromApacheCommons extends IsWindowsGuard instanceof Field
112
104
IsWindowsFromApacheCommons ( ) { isOsFromApacheCommons ( this , "IS_OS_WINDOWS" ) }
113
105
}
114
106
115
- private class IsAnyWindowsFromApacheCommons extends IsAnyWindowsGuard instanceof FieldAccess {
116
- IsAnyWindowsFromApacheCommons ( ) { isOsFromApacheCommons ( this , "IS_OS_WINDOWS_%" ) }
107
+ private class IsSpecificWindowsVariantFromApacheCommons extends IsSpecificWindowsVariant instanceof FieldAccess {
108
+ IsSpecificWindowsVariantFromApacheCommons ( ) { isOsFromApacheCommons ( this , "IS_OS_WINDOWS_%" ) }
117
109
}
118
110
119
111
private class IsUnixFromApacheCommons extends IsUnixGuard instanceof FieldAccess {
120
112
IsUnixFromApacheCommons ( ) { isOsFromApacheCommons ( this , "IS_OS_UNIX" ) }
121
113
}
122
114
123
- private class IsAnyUnixFromApacheCommons extends IsAnyUnixGuard instanceof FieldAccess {
124
- IsAnyUnixFromApacheCommons ( ) {
115
+ private class IsSpecificUnixVariantFromApacheCommons extends IsSpecificUnixVariant instanceof FieldAccess {
116
+ IsSpecificUnixVariantFromApacheCommons ( ) {
125
117
isOsFromApacheCommons ( this ,
126
118
[
127
119
"IS_OS_AIX" , "IS_OS_HP_UX" , "IS_OS_IRIX" , "IS_OS_LINUX" , "IS_OS_MAC%" , "IS_OS_FREE_BSD" ,
0 commit comments