Skip to content

Commit 0156fcc

Browse files
Apply suggestions from code review
Co-authored-by: Anders Schack-Mulligen <[email protected]>
1 parent 3a6665b commit 0156fcc

File tree

2 files changed

+21
-3
lines changed
  • java/ql
    • lib/semmle/code/java
    • test/library-tests/dataflow/stream-read

2 files changed

+21
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ private class InputStreamWrapperAnonymousStep extends AdditionalTaintStep {
232232
*/
233233
private class InputStreamWrapperConstructorStep extends AdditionalTaintStep {
234234
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
235-
exists(ClassInstanceExpr cc, Argument a, AssignExpr ae |
235+
exists(ClassInstanceExpr cc, Argument a, AssignExpr ae, int pos |
236236
cc.getConstructedType().getASourceSupertype+() instanceof TypeInputStream and
237-
cc.getAnArgument() = a and
238-
cc.getCallee().getParameter(a.getParameterPos()).getAnAccess() = ae.getRhs() and
237+
cc.getArgument(pragma[only_bind_into](pos)) = a and
238+
cc.getCallee().getParameter(pragma[only_bind_into](pos)).getAnAccess() = ae.getRhs() and
239239
ae.getDest().(FieldWrite).getField().getType().(RefType).getASourceSupertype*() instanceof
240240
TypeInputStream
241241
|

java/ql/test/library-tests/dataflow/stream-read/A.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,22 @@ public int read(byte[] b) throws IOException {
8484
sink(wrapper); // $ hasTaintFlow
8585
}
8686

87+
public static InputStream wrapStream(InputStream in) {
88+
return new InputStream() {
89+
@Override
90+
public int read() throws IOException {
91+
return 0;
92+
}
93+
94+
@Override
95+
public int read(byte[] b) throws IOException {
96+
return in.read(b);
97+
}
98+
};
99+
}
100+
101+
public static void testWrapCall() {
102+
sink(wrapStream(null)); // no flow
103+
sink(wrapStream(source())); // $ hasTaintFlow
104+
}
87105
}

0 commit comments

Comments
 (0)