Skip to content

Commit f9a207d

Browse files
committed
Java: migrate 'arg to arg' taint steps to CSV
1 parent 7e1534a commit f9a207d

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

java/ql/src/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,22 @@ private predicate summaryModelCsv(string row) {
226226
"org.apache.commons.io;IOUtils;false;toString;;;Argument[0];ReturnValue;taint",
227227
"java.net;URLDecoder;false;decode;;;Argument[0];ReturnValue;taint",
228228
"java.net;URI;false;create;;;Argument[0];ReturnValue;taint",
229-
"javax.xml.transform.sax;SAXSource;false;sourceToInputSource;;;Argument[0];ReturnValue;taint"
229+
"javax.xml.transform.sax;SAXSource;false;sourceToInputSource;;;Argument[0];ReturnValue;taint",
230+
// arg to arg
231+
"java.lang;System;false;arraycopy;;;Argument[0];Argument[2];taint",
232+
"org.apache.commons.io;IOUtils;false;copy;;;Argument[0];Argument[1];taint",
233+
"org.apache.commons.io;IOUtils;false;copyLarge;;;Argument[0];Argument[1];taint",
234+
"org.apache.commons.io;IOUtils;false;read;;;Argument[0];Argument[1];taint",
235+
"org.apache.commons.io;IOUtils;false;readFully;(InputStream,byte[]);;Argument[0];Argument[1];taint",
236+
"org.apache.commons.io;IOUtils;false;readFully;(InputStream,byte[],int,int);;Argument[0];Argument[1];taint",
237+
"org.apache.commons.io;IOUtils;false;readFully;(InputStream,ByteBuffer);;Argument[0];Argument[1];taint",
238+
"org.apache.commons.io;IOUtils;false;readFully;(ReadableByteChannel,ByteBuffer);;Argument[0];Argument[1];taint",
239+
"org.apache.commons.io;IOUtils;false;readFully;(Reader,char[]);;Argument[0];Argument[1];taint",
240+
"org.apache.commons.io;IOUtils;false;readFully;(Reader,char[],int,int);;Argument[0];Argument[1];taint",
241+
"org.apache.commons.io;IOUtils;false;write;;;Argument[0];Argument[1];taint",
242+
"org.apache.commons.io;IOUtils;false;writeChunked;;;Argument[0];Argument[1];taint",
243+
"org.apache.commons.io;IOUtils;false;writeLines;;;Argument[0];Argument[2];taint",
244+
"org.apache.commons.io;IOUtils;false;writeLines;;;Argument[1];Argument[2];taint"
230245
]
231246
}
232247

java/ql/src/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -383,48 +383,13 @@ private predicate taintPreservingArgumentToMethod(Method method, int arg) {
383383
*/
384384
private predicate argToArgStep(Expr tracked, Expr sink) {
385385
exists(MethodAccess ma, Method method, int input, int output |
386-
taintPreservingArgToArg(method, argToParam(ma, input), argToParam(ma, output)) and
386+
method.(TaintPreservingCallable).transfersTaint(argToParam(ma, input), argToParam(ma, output)) and
387387
ma.getMethod() = method and
388388
ma.getArgument(input) = tracked and
389389
ma.getArgument(output) = sink
390390
)
391391
}
392392

393-
/**
394-
* Holds if `method` is a library method that writes tainted data to the
395-
* `output`th argument if the `input`th argument is tainted.
396-
*/
397-
private predicate taintPreservingArgToArg(Method method, int input, int output) {
398-
method.getDeclaringType().hasQualifiedName("org.apache.commons.io", "IOUtils") and
399-
(
400-
method.hasName("copy") and input = 0 and output = 1
401-
or
402-
method.hasName("copyLarge") and input = 0 and output = 1
403-
or
404-
method.hasName("read") and input = 0 and output = 1
405-
or
406-
method.hasName("readFully") and
407-
input = 0 and
408-
output = 1 and
409-
not method.getParameterType(1).hasName("int")
410-
or
411-
method.hasName("write") and input = 0 and output = 1
412-
or
413-
method.hasName("writeChunked") and input = 0 and output = 1
414-
or
415-
method.hasName("writeLines") and input = 0 and output = 2
416-
or
417-
method.hasName("writeLines") and input = 1 and output = 2
418-
)
419-
or
420-
method.getDeclaringType().hasQualifiedName("java.lang", "System") and
421-
method.hasName("arraycopy") and
422-
input = 0 and
423-
output = 2
424-
or
425-
method.(TaintPreservingCallable).transfersTaint(input, output)
426-
}
427-
428393
/**
429394
* Holds if `tracked` is the argument of a method that transfers taint
430395
* from the argument to the qualifier and `sink` is the qualifier.

0 commit comments

Comments
 (0)