Skip to content

Commit f36bb8b

Browse files
author
Benjamin Muskalla
committed
Exclude models for simpler types
Avoid generating models for types that can't really propagate taint in a valuable way (e.g. primitivies, BigInt, ..). Keep tracking bulk-like data (e.g. char[] or byte[]).
1 parent 842f617 commit f36bb8b

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

java/ql/src/utils/model-generator/CaptureSummaryModels.ql

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ string captureFieldFlow(Callable api) {
3131
exists(FieldAccess fa, ReturnNodeExt postUpdate |
3232
not (fa.getField().isStatic() and fa.getField().isFinal()) and
3333
postUpdate.getEnclosingCallable() = api and
34-
not api.getReturnType() instanceof PrimitiveType and
34+
isRelevantType(api.getReturnType()) and
3535
not api.getDeclaringType() instanceof EnumType and
3636
TaintTracking::localTaint(DataFlow::exprNode(fa), postUpdate)
3737
|
@@ -55,7 +55,7 @@ class ParameterToFieldConfig extends TaintTracking::Configuration {
5555

5656
override predicate isSource(DataFlow::Node source) {
5757
source instanceof DataFlow::ParameterNode and
58-
not source.getType() instanceof PrimitiveType
58+
isRelevantType(source.getType())
5959
}
6060

6161
override predicate isSink(DataFlow::Node sink) {
@@ -82,10 +82,8 @@ class ParameterToReturnValueTaintConfig extends TaintTracking::Configuration {
8282
exists(Callable api |
8383
source instanceof DataFlow::ParameterNode and
8484
api = source.asParameter().getCallable() and
85-
not api.getReturnType() instanceof PrimitiveType and
86-
not api.getReturnType() instanceof TypeClass and
87-
not source.asParameter().getType() instanceof PrimitiveType and
88-
not source.asParameter().getType() instanceof TypeClass
85+
isRelevantType(api.getReturnType()) and
86+
isRelevantType(source.asParameter().getType())
8987
)
9088
}
9189

@@ -120,6 +118,18 @@ string captureParameterToParameterFlow(Callable api) {
120118
)
121119
}
122120

121+
predicate isRelevantType(Type t) {
122+
not t instanceof TypeClass and
123+
not t instanceof EnumType and
124+
not t instanceof PrimitiveType and
125+
not t instanceof BoxedType and
126+
not t.(RefType).hasQualifiedName("java.math", "BigInteger") and
127+
not t.(Array).getElementType() instanceof PrimitiveType and
128+
not t.(Array).getElementType().(PrimitiveType).getName().regexpMatch("byte|char") and
129+
not t.(Array).getElementType() instanceof BoxedType and
130+
not t.(CollectionType).getElementType() instanceof BoxedType
131+
}
132+
123133
// TODO: "com.google.common.base;Converter;true;convertAll;(Iterable);;Element of Argument[0];Element of ReturnValue;taint",
124134
// TODO: infer interface from multiple implementations? e.g. UriComponentsContributor
125135
// TODO: distinguish between taint and value flows. If we find a value flow, omit the taint flow

java/ql/test/utils/model-generator/p/Pojo.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package p;
22

3+
import java.math.BigInteger;
4+
import java.util.Collection;
35
import java.util.List;
46

57
public final class Pojo {
@@ -37,6 +39,34 @@ public int getIntValue() {
3739
return intValue;
3840
}
3941

42+
public Integer getBoxedValue() {
43+
return Integer.valueOf(intValue);
44+
}
45+
46+
public int[] getPrimitiveArray() {
47+
return new int[] { intValue };
48+
}
49+
50+
public char[] getCharArray() {
51+
return Character.toChars(intValue);
52+
}
53+
54+
public byte[] getByteArray() {
55+
return new byte[] { (byte) intValue };
56+
}
57+
58+
public Integer[] getBoxedArray() {
59+
return new Integer[] { Integer.valueOf(intValue) };
60+
}
61+
62+
public Collection<Integer> getBoxedCollection() {
63+
return List.of(Integer.valueOf(intValue));
64+
}
65+
66+
public BigInteger getBigInt() {
67+
return BigInteger.valueOf(intValue);
68+
}
69+
4070
public void fillIn(List<String> target) {
4171
target.add(value);
4272
}

0 commit comments

Comments
 (0)