Skip to content

Commit dc247e0

Browse files
authored
Merge pull request #20383 from aschackmull/java/fix-more-broken-perf
Java: Fix more broken performance.
2 parents 84df8f9 + 4c1fa58 commit dc247e0

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,23 @@ private predicate inputStreamWrapper(Constructor c, int argi) {
278278

279279
/** An object construction that preserves the data flow status of any of its arguments. */
280280
private predicate constructorStep(Expr tracked, ConstructorCall sink, string model) {
281-
exists(int argi | sink.getArgument(argi) = tracked |
281+
exists(int argi | sink.getArgument(pragma[only_bind_into](argi)) = tracked |
282282
// wrappers constructed by extension
283283
exists(Constructor c, Parameter p, SuperConstructorInvocationStmt sup |
284284
c = sink.getConstructor() and
285-
p = c.getParameter(argi) and
285+
p = c.getParameter(pragma[only_bind_into](argi)) and
286286
sup.getEnclosingCallable() = c and
287287
constructorStep(p.getAnAccess(), sup, model)
288288
)
289289
or
290290
// a custom InputStream that wraps a tainted data source is tainted
291291
model = "inputStreamWrapper" and
292-
inputStreamWrapper(sink.getConstructor(), argi)
292+
inputStreamWrapper(sink.getConstructor(), pragma[only_bind_into](argi))
293293
or
294294
model = "TaintPreservingCallable" and
295-
sink.getConstructor().(TaintPreservingCallable).returnsTaintFrom(argToParam(sink, argi))
295+
sink.getConstructor()
296+
.(TaintPreservingCallable)
297+
.returnsTaintFrom(argToParam(sink, pragma[only_bind_into](argi)))
296298
)
297299
}
298300

java/ql/lib/semmle/code/java/frameworks/android/ExternalStorage.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ private predicate externalStorageFlowStep(DataFlow::Node node1, DataFlow::Node n
2020
node2.asExpr().(FieldRead).getField().getInitializer() = node1.asExpr()
2121
}
2222

23-
private predicate externalStorageFlow(DataFlow::Node node1, DataFlow::Node node2) {
24-
externalStorageFlowStep*(node1, node2)
23+
private predicate externalStorageDirFlowsTo(DataFlow::Node n) {
24+
sourceNode(n, "android-external-storage-dir")
25+
or
26+
exists(DataFlow::Node mid | externalStorageDirFlowsTo(mid) and externalStorageFlowStep(mid, n))
2527
}
2628

2729
/**
2830
* Holds if `n` is a node that reads the contents of an external file in Android.
2931
* This is controllable by third-party applications, so is treated as a remote flow source.
3032
*/
3133
predicate androidExternalStorageSource(DataFlow::Node n) {
32-
exists(DataFlow::Node externalDir, DirectFileReadExpr read |
33-
sourceNode(externalDir, "android-external-storage-dir") and
34+
exists(DirectFileReadExpr read |
3435
n.asExpr() = read and
35-
externalStorageFlow(externalDir, DataFlow::exprNode(read.getFileExpr()))
36+
externalStorageDirFlowsTo(DataFlow::exprNode(read.getFileExpr()))
3637
)
3738
}

java/ql/src/Likely Bugs/Collections/ContainsTypeMismatch.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ predicate containerAccess(string package, string type, int p, string signature,
9999
class MismatchedContainerAccess extends MethodCall {
100100
MismatchedContainerAccess() {
101101
exists(string package, string type, int i |
102-
containerAccess(package, type, _, this.getCallee().getSignature(), i)
102+
containerAccess(package, type, _, this.getCallee().getSignature(), pragma[only_bind_into](i))
103103
|
104104
this.getCallee()
105105
.getDeclaringType()
106106
.getSourceDeclaration()
107107
.getASourceSupertype*()
108108
.hasQualifiedName(package, type) and
109-
this.getCallee().getParameter(i).getType() instanceof TypeObject
109+
this.getCallee().getParameter(pragma[only_bind_into](i)).getType() instanceof TypeObject
110110
)
111111
}
112112

java/ql/src/Likely Bugs/Collections/RemoveTypeMismatch.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ predicate containerModification(string package, string type, int p, string signa
6969
class MismatchedContainerModification extends MethodCall {
7070
MismatchedContainerModification() {
7171
exists(string package, string type, int i |
72-
containerModification(package, type, _, this.getCallee().getSignature(), i)
72+
containerModification(package, type, _, this.getCallee().getSignature(),
73+
pragma[only_bind_into](i))
7374
|
7475
this.getCallee()
7576
.getDeclaringType()
7677
.getASourceSupertype*()
7778
.getSourceDeclaration()
7879
.hasQualifiedName(package, type) and
79-
this.getCallee().getParameter(i).getType() instanceof TypeObject
80+
this.getCallee().getParameter(pragma[only_bind_into](i)).getType() instanceof TypeObject
8081
)
8182
}
8283

java/ql/src/Likely Bugs/Frameworks/Swing/BadlyOverriddenAdapter.ql

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ class Adapter extends Class {
2424
}
2525
}
2626

27-
from Class c, Adapter adapter, Method m
28-
where
27+
pragma[nomagic]
28+
predicate candidate(Class c, Adapter adapter, Method m, string name) {
2929
adapter = c.getASupertype() and
3030
c = m.getDeclaringType() and
31-
exists(Method original | adapter = original.getDeclaringType() | m.getName() = original.getName()) and
32-
not exists(Method overridden | adapter = overridden.getDeclaringType() | m.overrides(overridden)) and
31+
name = m.getName() and
3332
// The method is not used for any other purpose.
3433
not exists(MethodCall ma | ma.getMethod() = m)
34+
}
35+
36+
from Class c, Adapter adapter, Method m, string name
37+
where
38+
candidate(c, adapter, m, name) and
39+
exists(Method original | adapter = original.getDeclaringType() | name = original.getName()) and
40+
not exists(Method overridden | adapter = overridden.getDeclaringType() | m.overrides(overridden))
3541
select m,
3642
"Method " + m.getName() + " attempts to override a method in " + adapter.getName() +
3743
", but does not have the same argument types. " + m.getName() +

java/ql/src/Likely Bugs/Likely Typos/SelfAssignment.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java
1515

16+
pragma[nomagic]
1617
predicate toCompare(VarAccess left, VarAccess right) {
1718
exists(AssignExpr assign | assign.getDest() = left and assign.getSource() = right)
1819
or
@@ -29,17 +30,21 @@ predicate local(RefType enclosingType, VarAccess v) {
2930
not exists(v.getQualifier()) and enclosingType = v.getEnclosingCallable().getDeclaringType()
3031
}
3132

33+
pragma[nomagic]
3234
predicate sameVariable(VarAccess left, VarAccess right) {
3335
toCompare(left, right) and
34-
left.getVariable() = right.getVariable() and
36+
pragma[only_bind_out](left.getVariable()) = pragma[only_bind_out](right.getVariable()) and
3537
(
3638
exists(Expr q1, Expr q2 |
3739
q1 = left.getQualifier() and
3840
sameVariable(q1, q2) and
3941
q2 = right.getQualifier()
4042
)
4143
or
42-
exists(RefType enclosingType | local(enclosingType, left) and local(enclosingType, right))
44+
exists(RefType enclosingType |
45+
local(enclosingType, pragma[only_bind_out](left)) and
46+
local(enclosingType, pragma[only_bind_out](right))
47+
)
4348
)
4449
}
4550

0 commit comments

Comments
 (0)