Skip to content

Commit 1de6845

Browse files
committed
Move steps to InputStream.qll
1 parent 0156fcc commit 1de6845

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed

java/ql/lib/semmle/code/java/JDK.qll

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import Member
66
import semmle.code.java.security.ExternalProcess
7-
private import semmle.code.java.dataflow.DataFlow
87
private import semmle.code.java.dataflow.FlowSteps
98

109
// --- Standard types ---
@@ -203,48 +202,6 @@ class TypeFile extends Class {
203202
TypeFile() { this.hasQualifiedName("java.io", "File") }
204203
}
205204

206-
/**
207-
* A taint step from an update of the `bytes[]` parameter in an override of the `InputStream.read` method
208-
* to a class instance expression of the type extending `InputStream`.
209-
*
210-
* This models how a subtype of `InputStream` could be tainted by the definition of its methods, which will
211-
* normally only happen in anonymous classes.
212-
*/
213-
private class InputStreamWrapperAnonymousStep extends AdditionalTaintStep {
214-
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
215-
exists(Method m, AnonymousClass wrapper |
216-
m.hasName("read") and
217-
m.getDeclaringType() = wrapper and
218-
wrapper.getASourceSupertype+() instanceof TypeInputStream
219-
|
220-
n1.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr() = m.getParameter(0).getAnAccess() and
221-
n2.asExpr() = wrapper.getClassInstanceExpr()
222-
)
223-
}
224-
}
225-
226-
/**
227-
* A taint step from an `InputStream` argument of the constructor of an `InputStream` subtype
228-
* to the call of the constructor, only if the argument is assigned to a class field.
229-
*
230-
* This models how it's assumed that an `InputStream` wrapper is tainted by the wrapped stream,
231-
* and is a workaround to low `fieldFlowBranchLimit`s in dataflow configurations.
232-
*/
233-
private class InputStreamWrapperConstructorStep extends AdditionalTaintStep {
234-
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
235-
exists(ClassInstanceExpr cc, Argument a, AssignExpr ae, int pos |
236-
cc.getConstructedType().getASourceSupertype+() instanceof TypeInputStream and
237-
cc.getArgument(pragma[only_bind_into](pos)) = a and
238-
cc.getCallee().getParameter(pragma[only_bind_into](pos)).getAnAccess() = ae.getRhs() and
239-
ae.getDest().(FieldWrite).getField().getType().(RefType).getASourceSupertype*() instanceof
240-
TypeInputStream
241-
|
242-
n1.asExpr() = a and
243-
n2.asExpr() = cc
244-
)
245-
}
246-
}
247-
248205
// --- Standard methods ---
249206
/**
250207
* DEPRECATED: Any constructor of class `java.lang.ProcessBuilder`.

java/ql/lib/semmle/code/java/dataflow/FlowSteps.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ private module Frameworks {
2020
private import semmle.code.java.frameworks.Guice
2121
private import semmle.code.java.frameworks.IoJsonWebToken
2222
private import semmle.code.java.frameworks.jackson.JacksonSerializability
23+
private import semmle.code.java.frameworks.InputStream
2324
private import semmle.code.java.frameworks.Properties
2425
private import semmle.code.java.frameworks.Protobuf
2526
private import semmle.code.java.frameworks.ratpack.RatpackExec
2627
private import semmle.code.java.frameworks.stapler.Stapler
27-
private import semmle.code.java.JDK
2828
}
2929

3030
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/** Provides definitions related to `java.io.InputStream`. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.DataFlow
5+
private import semmle.code.java.dataflow.FlowSteps
6+
7+
/**
8+
* A taint step from an update of the `bytes[]` parameter in an override of the `InputStream.read` method
9+
* to a class instance expression of the type extending `InputStream`.
10+
*
11+
* This models how a subtype of `InputStream` could be tainted by the definition of its methods, which will
12+
* normally only happen in anonymous classes.
13+
*/
14+
private class InputStreamWrapperAnonymousStep extends AdditionalTaintStep {
15+
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
16+
exists(Method m, AnonymousClass wrapper |
17+
m.hasName("read") and
18+
m.getDeclaringType() = wrapper and
19+
wrapper.getASourceSupertype+() instanceof TypeInputStream
20+
|
21+
n1.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr() = m.getParameter(0).getAnAccess() and
22+
n2.asExpr() = wrapper.getClassInstanceExpr()
23+
)
24+
}
25+
}
26+
27+
/**
28+
* A taint step from an `InputStream` argument of the constructor of an `InputStream` subtype
29+
* to the call of the constructor, only if the argument is assigned to a class field.
30+
*
31+
* This models how it's assumed that an `InputStream` wrapper is tainted by the wrapped stream,
32+
* and is a workaround to low `fieldFlowBranchLimit`s in dataflow configurations.
33+
*/
34+
private class InputStreamWrapperConstructorStep extends AdditionalTaintStep {
35+
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
36+
exists(ClassInstanceExpr cc, Argument a, AssignExpr ae, int pos |
37+
cc.getConstructedType().getASourceSupertype+() instanceof TypeInputStream and
38+
cc.getArgument(pragma[only_bind_into](pos)) = a and
39+
cc.getCallee().getParameter(pragma[only_bind_into](pos)).getAnAccess() = ae.getRhs() and
40+
ae.getDest().(FieldWrite).getField().getType().(RefType).getASourceSupertype*() instanceof
41+
TypeInputStream
42+
|
43+
n1.asExpr() = a and
44+
n2.asExpr() = cc
45+
)
46+
}
47+
}

0 commit comments

Comments
 (0)