|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import java |
6 | | -import semmle.code.java.controlflow.Guards |
7 | 6 |
|
8 | 7 | /** Models the creation of a path. */ |
9 | 8 | abstract class PathCreation extends Expr { |
@@ -140,29 +139,3 @@ private class FileOutputStreamCreation extends PathCreation, ClassInstanceExpr { |
140 | 139 | result.getType() instanceof TypeString |
141 | 140 | } |
142 | 141 | } |
143 | | - |
144 | | -private predicate inWeakCheck(Expr e) { |
145 | | - // None of these are sufficient to guarantee that a string is safe. |
146 | | - exists(MethodAccess m, Method def | m.getQualifier() = e and m.getMethod() = def | |
147 | | - def.getName() = "startsWith" or |
148 | | - def.getName() = "endsWith" or |
149 | | - def.getName() = "isEmpty" or |
150 | | - def.getName() = "equals" |
151 | | - ) |
152 | | - or |
153 | | - // Checking against `null` has no bearing on path traversal. |
154 | | - exists(EqualityTest b | b.getAnOperand() = e | b.getAnOperand() instanceof NullLiteral) |
155 | | -} |
156 | | - |
157 | | -// Ignore cases where the variable has been checked somehow, |
158 | | -// but allow some particularly obviously bad cases. |
159 | | -predicate guarded(VarAccess e) { |
160 | | - exists(PathCreation p | e = p.getAnInput()) and |
161 | | - exists(ConditionBlock cb, Expr c | |
162 | | - cb.getCondition().getAChildExpr*() = c and |
163 | | - c = e.getVariable().getAnAccess() and |
164 | | - cb.controls(e.getBasicBlock(), true) and |
165 | | - // Disallow a few obviously bad checks. |
166 | | - not inWeakCheck(c) |
167 | | - ) |
168 | | -} |
0 commit comments