|
1 | 1 | /** Definitions related to the Apache Commons Lang library. */ |
2 | 2 |
|
3 | 3 | import java |
| 4 | +private import semmle.code.java.dataflow.FlowSteps |
4 | 5 |
|
5 | | -/*--- Types ---*/ |
6 | | -/** The class `org.apache.commons.lang.RandomStringUtils` or `org.apache.commons.lang3.RandomStringUtils`. */ |
| 6 | +/** |
| 7 | + * The class `org.apache.commons.lang.RandomStringUtils` or `org.apache.commons.lang3.RandomStringUtils`. |
| 8 | + */ |
7 | 9 | class TypeApacheRandomStringUtils extends Class { |
8 | 10 | TypeApacheRandomStringUtils() { |
9 | | - hasQualifiedName("org.apache.commons.lang", "RandomStringUtils") or |
10 | | - hasQualifiedName("org.apache.commons.lang3", "RandomStringUtils") |
| 11 | + this.hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"], |
| 12 | + "RandomStringUtils") |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * The class `org.apache.commons.lang.ArrayUtils` or `org.apache.commons.lang3.ArrayUtils`. |
| 18 | + */ |
| 19 | +class TypeApacheArrayUtils extends Class { |
| 20 | + TypeApacheArrayUtils() { |
| 21 | + hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"], "ArrayUtils") |
11 | 22 | } |
12 | 23 | } |
13 | 24 |
|
14 | | -/*--- Methods ---*/ |
15 | 25 | /** |
16 | 26 | * The method `deserialize` in either `org.apache.commons.lang.SerializationUtils` |
17 | 27 | * or `org.apache.commons.lang3.SerializationUtils`. |
18 | 28 | */ |
19 | 29 | class MethodApacheSerializationUtilsDeserialize extends Method { |
20 | 30 | MethodApacheSerializationUtilsDeserialize() { |
21 | | - ( |
22 | | - this.getDeclaringType().hasQualifiedName("org.apache.commons.lang", "SerializationUtils") or |
23 | | - this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "SerializationUtils") |
24 | | - ) and |
| 31 | + this.getDeclaringType() |
| 32 | + .hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"], |
| 33 | + "SerializationUtils") and |
25 | 34 | this.hasName("deserialize") |
26 | 35 | } |
27 | 36 | } |
| 37 | + |
| 38 | +/** |
| 39 | + * A taint preserving method on `org.apache.commons.lang.ArrayUtils` or `org.apache.commons.lang3.ArrayUtils` |
| 40 | + */ |
| 41 | +private class ApacheLangArrayUtilsTaintPreservingMethod extends TaintPreservingCallable { |
| 42 | + ApacheLangArrayUtilsTaintPreservingMethod() { |
| 43 | + this.getDeclaringType() instanceof TypeApacheArrayUtils |
| 44 | + } |
| 45 | + |
| 46 | + override predicate returnsTaintFrom(int src) { |
| 47 | + this.hasName(["addAll", "addFirst"]) and |
| 48 | + src = [0 .. getNumberOfParameters() - 1] |
| 49 | + or |
| 50 | + this.hasName([ |
| 51 | + "clone", "nullToEmpty", "remove", "removeAll", "removeElement", "removeElements", "reverse", |
| 52 | + "shift", "shuffle", "subarray", "swap", "toArray", "toMap", "toObject", "toPrimitive", |
| 53 | + "toString", "toStringArray" |
| 54 | + ]) and |
| 55 | + src = 0 |
| 56 | + or |
| 57 | + this.hasName("add") and |
| 58 | + this.getNumberOfParameters() = 2 and |
| 59 | + src = [0, 1] |
| 60 | + or |
| 61 | + this.hasName("add") and |
| 62 | + this.getNumberOfParameters() = 3 and |
| 63 | + src = [0, 2] |
| 64 | + } |
| 65 | +} |
0 commit comments