3
3
import java
4
4
private import semmle.code.java.dataflow.DataFlow
5
5
private import semmle.code.java.dataflow.FlowSteps
6
+ private import semmle.code.java.dataflow.SSA
7
+ private import semmle.code.java.dataflow.TaintTracking
6
8
7
9
/**
8
- * A taint step from an update of the `bytes[]` parameter in an override of the `InputStream.read` method
10
+ * A local taint step from the definition of a captured variable, the capturer of which
11
+ * updates the `bytes[]` parameter in an override of the `InputStream.read` method,
9
12
* to a class instance expression of the type extending `InputStream`.
10
13
*
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 .
14
+ * This models how a subtype of `InputStream` could be tainted by capturing tainted variables in
15
+ * the definition of its methods .
13
16
*/
14
- private class InputStreamWrapperAnonymousStep extends AdditionalTaintStep {
17
+ private class InputStreamWrapperCapturedLocalStep extends AdditionalTaintStep {
15
18
override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
16
- exists ( Method m , NestedClass wrapper |
17
- m . hasName ( "read" ) and
19
+ exists ( InputStreamRead m , NestedClass wrapper , SsaVariable captured , SsaImplicitInit capturer |
20
+ wrapper . getASourceSupertype + ( ) instanceof TypeInputStream and
18
21
m .getDeclaringType ( ) = wrapper and
19
- wrapper .getASourceSupertype + ( ) instanceof TypeInputStream
20
- |
21
- n1 .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) = m .getParameter ( 0 ) .getAnAccess ( ) and
22
+ capturer .captures ( captured ) and
23
+ TaintTracking:: localTaint ( DataFlow:: exprNode ( capturer .getAFirstUse ( ) ) ,
24
+ any ( DataFlow:: PostUpdateNode pun |
25
+ pun .getPreUpdateNode ( ) .asExpr ( ) = m .getParameter ( 0 ) .getAnAccess ( )
26
+ ) ) and
22
27
n2 .asExpr ( )
23
28
.( ClassInstanceExpr )
24
29
.getConstructedType ( )
25
30
.getASourceSupertype * ( )
26
31
.getSourceDeclaration ( ) = wrapper
32
+ |
33
+ n1 .asExpr ( ) = captured .( SsaExplicitUpdate ) .getDefiningExpr ( ) .( VariableAssign ) .getSource ( )
34
+ or
35
+ captured .( SsaImplicitInit ) .isParameterDefinition ( n1 .asParameter ( ) )
27
36
)
28
37
}
29
38
}
@@ -49,3 +58,10 @@ private class InputStreamWrapperConstructorStep extends AdditionalTaintStep {
49
58
)
50
59
}
51
60
}
61
+
62
+ private class InputStreamRead extends Method {
63
+ InputStreamRead ( ) {
64
+ this .hasName ( "read" ) and
65
+ this .getDeclaringType ( ) .getASourceSupertype * ( ) instanceof TypeInputStream
66
+ }
67
+ }
0 commit comments