Skip to content

Commit ae23920

Browse files
author
Max Schaefer
committed
Fix spurious source models for primitive types in framework mode.
1 parent 9975f97 commit ae23920

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,15 @@ newtype TFrameworkModeEndpoint =
3838
} or
3939
TOverridableParameter(Method m, Parameter p) {
4040
AutomodelJavaUtil::isFromSource(p) and
41+
not AutomodelJavaUtil::isUnexploitableType(p.getType()) and
4142
p.getCallable() = m and
4243
m instanceof ModelExclusions::ModelApi and
43-
not m.getDeclaringType().isFinal() and
44-
not m.isFinal() and
45-
not m.isStatic()
44+
AutomodelJavaUtil::isOverridable(m)
4645
} or
4746
TOverridableQualifier(Method m) {
4847
AutomodelJavaUtil::isFromSource(m) and
4948
m instanceof ModelExclusions::ModelApi and
50-
not m.getDeclaringType().isFinal() and
51-
not m.isFinal() and
52-
not m.isStatic()
49+
AutomodelJavaUtil::isOverridable(m)
5350
}
5451

5552
/**

java/ql/automodel/src/AutomodelJavaUtil.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ predicate isUnexploitableType(Type tp) {
111111
tp instanceof NumberType or
112112
tp instanceof VoidType
113113
}
114+
115+
/**
116+
* Holds if the given method can be overridden, that is, it is not final,
117+
* static, or private.
118+
*/
119+
predicate isOverridable(Method m) {
120+
not m.getDeclaringType().isFinal() and not m.isFinal() and
121+
not m.isStatic() and not m.isPrivate()
122+
}

java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public int compareTo( // $ negativeExample=compareTo(File):Argument[this] negati
77
return 0;
88
}
99

10-
public boolean setLastModified(long time) { // $ sinkModel=setLastModified(long):Argument[this] sourceModel=setLastModified(long):Parameter[this] SPURIOUS: sourceModel=setLastModified(long):Parameter[0] // time is not a candidate (primitive type)
10+
public boolean setLastModified(long time) { // $ sinkModel=setLastModified(long):Argument[this] sourceModel=setLastModified(long):Parameter[this] // time is not a candidate (primitive type)
1111
return false;
1212
} // return value is not a source candidate because it's a primitive
1313
}

0 commit comments

Comments
 (0)