Skip to content

Commit 5d487b9

Browse files
Java: Merge TaintPreservingMethod with TaintTransferringMethod
1 parent a510f58 commit 5d487b9

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,23 @@ class AdditionalTaintStep extends Unit {
3232
}
3333

3434
/**
35-
* A method that returns tainted data when one of its inputs (an argument or the qualifier) is tainted.
35+
* A method that preserves taint.
3636
*
37-
* Extend this class to add additional taint steps through a method that should
38-
* apply to all taint configurations.
37+
* Extend this class and override at least one of `returnsTaint` or `transfersTaint`
38+
* to add additional taint steps through a method that should apply to all taint configurations.
3939
*/
4040
abstract class TaintPreservingMethod extends Method {
4141
/**
4242
* Holds if this method returns tainted data when `arg` tainted.
4343
* `arg` is a parameter index, or is -1 to indicate the qualifier.
4444
*/
45-
abstract predicate returnsTaint(int arg);
46-
}
45+
predicate returnsTaint(int arg) { none() }
4746

48-
/**
49-
* A method that transfers taint from one of its inputs (an argument or the qualifier) to another.
50-
*
51-
* Extend this class to add additional taint steps through a method that should
52-
* apply to all taint configurations.
53-
*/
54-
abstract class TaintTransferringMethod extends Method {
5547
/**
5648
* Holds if this method writes tainted data to `sink` when `src` is tainted.
5749
* `src` and `sink` are parameter indices, or -1 to indicate the qualifier.
5850
*/
59-
abstract predicate transfersTaint(int src, int sink);
51+
predicate transfersTaint(int src, int sink) { none() }
6052
}
6153

6254
private class StringTaintPreservingMethod extends TaintPreservingMethod {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private predicate taintPreservingQualifierToArgument(Method m, int arg) {
296296
m.hasName("read") and
297297
arg = 0
298298
or
299-
m.(TaintTransferringMethod).transfersTaint(-1, arg)
299+
m.(TaintPreservingMethod).transfersTaint(-1, arg)
300300
}
301301

302302
/** Access to a method that passes taint from the qualifier. */
@@ -571,7 +571,7 @@ private predicate taintPreservingArgToArg(Method method, int input, int output)
571571
input = 0 and
572572
output = 2
573573
or
574-
method.(TaintTransferringMethod).transfersTaint(input, output)
574+
method.(TaintPreservingMethod).transfersTaint(input, output)
575575
}
576576

577577
/**
@@ -610,7 +610,7 @@ private predicate taintPreservingArgumentToQualifier(Method method, int arg) {
610610
append.getDeclaringType().hasQualifiedName("java.io", "StringWriter")
611611
)
612612
or
613-
method.(TaintTransferringMethod).transfersTaint(arg, -1)
613+
method.(TaintPreservingMethod).transfersTaint(arg, -1)
614614
}
615615

616616
/** A comparison or equality test with a constant. */
@@ -734,7 +734,7 @@ private class TypeFormatter extends Class {
734734
TypeFormatter() { this.hasQualifiedName("java.util", "Formatter") }
735735
}
736736

737-
private class FormatterMethod extends TaintPreservingMethod, TaintTransferringMethod {
737+
private class FormatterMethod extends TaintPreservingMethod {
738738
FormatterMethod() {
739739
getDeclaringType() instanceof TypeFormatter and
740740
hasName(["format", "out", "toString"])

java/ql/src/semmle/code/java/frameworks/android/SQLite.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private class QueryBuilderBuildMethod extends TaintPreservingMethod {
256256
override predicate returnsTaint(int arg) { argument = arg }
257257
}
258258

259-
private class QueryBuilderAppendMethod extends TaintTransferringMethod {
259+
private class QueryBuilderAppendMethod extends TaintPreservingMethod {
260260
QueryBuilderAppendMethod() {
261261
this.getDeclaringType().getASourceSupertype*() instanceof TypeSQLiteQueryBuilder and
262262
// setProjectionMap(Map<String, String> columnMap)

java/ql/src/semmle/code/java/frameworks/jackson/JacksonSerializability.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class JacksonSerializableType extends Type { }
2828
* A method used for serializing objects using Jackson. The final parameter is the object to be
2929
* serialized.
3030
*/
31-
library class JacksonWriteValueMethod extends TaintPreservingMethod, TaintTransferringMethod {
31+
library class JacksonWriteValueMethod extends TaintPreservingMethod {
3232
JacksonWriteValueMethod() {
3333
(
3434
getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectWriter") or

0 commit comments

Comments
 (0)