Skip to content

Commit cdea0f0

Browse files
authored
Merge pull request github#3946 from aibaars/util-collections-2
Java: Clean up ContainerFlow: address outstanding comments
2 parents 71933a4 + b1e604b commit cdea0f0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ private predicate taintPreservingQualifierToMethod(Method m) {
130130
m.(CollectionMethod).hasName(["peek", "pop"])
131131
or
132132
// java.util.Queue
133+
// covered by Stack: peek()
133134
m.(CollectionMethod).hasName(["element", "poll"])
134135
or
135136
m.(CollectionMethod).hasName("remove") and m.getNumberOfParameters() = 0
@@ -254,7 +255,7 @@ private predicate taintPreservingArgumentToQualifier(Method method, int arg) {
254255
// covered by Deque: offerFirst(E, long, TimeUnit), offerLast(E, long, TimeUnit)
255256
method.(CollectionMethod).hasName(["putFirst", "putLast"]) and arg = 0
256257
or
257-
//java.util.Dictionary
258+
// java.util.Dictionary
258259
method
259260
.getDeclaringType()
260261
.getSourceDeclaration()
@@ -269,9 +270,6 @@ private predicate taintPreservingArgumentToQualifier(Method method, int arg) {
269270
* `arg`th argument is tainted.
270271
*/
271272
private predicate taintPreservingArgumentToMethod(Method method, int arg) {
272-
// java.util.Stack
273-
method.(CollectionMethod).hasName("push") and arg = 0
274-
or
275273
method.getDeclaringType().hasQualifiedName("java.util", "Collections") and
276274
(
277275
method

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,18 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
413413
m.hasName("toString") and node1.asExpr() = ma.getArgument(1)
414414
)
415415
)
416+
or
417+
exists(MethodAccess ma, Method m |
418+
ma = node2.asExpr() and
419+
m = ma.getMethod() and
420+
m
421+
.getDeclaringType()
422+
.getSourceDeclaration()
423+
.getASourceSupertype*()
424+
.hasQualifiedName("java.util", "Stack") and
425+
m.hasName("push") and
426+
node1.asExpr() = ma.getArgument(0)
427+
)
416428
}
417429

418430
/**

0 commit comments

Comments
 (0)