Skip to content

Commit 5d73b99

Browse files
committed
Java: ContainerFlow: organize taintPreservingQualifierToMethod
1 parent 993506d commit 5d73b99

File tree

1 file changed

+61
-17
lines changed

1 file changed

+61
-17
lines changed

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

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,45 +89,89 @@ class ContainerType extends RefType {
8989
}
9090

9191
private predicate taintPreservingQualifierToMethod(Method m) {
92+
// java.util.Map.Entry
9293
m.getDeclaringType() instanceof EntryType and
93-
m.hasName("getValue")
94+
m.hasName(["getValue", "setValue"])
9495
or
96+
// java.util.Iterable
9597
m.getDeclaringType() instanceof IterableType and
96-
m.hasName("iterator")
98+
m.hasName(["iterator", "spliterator"])
9799
or
100+
// java.util.Iterator
98101
m.getDeclaringType() instanceof IteratorType and
99102
m.hasName("next")
100103
or
104+
// java.util.ListIterator
105+
m.getDeclaringType() instanceof IteratorType and
106+
m.hasName("previous")
107+
or
108+
// java.util.Enumeration
101109
m.getDeclaringType() instanceof EnumerationType and
102-
m.hasName("nextElement")
110+
m.hasName(["asIterator", "nextElement"])
111+
or
112+
// java.util.Map
113+
m
114+
.(MapMethod)
115+
.hasName(["compute", "computeIfAbsent", "computeIfPresent", "entrySet", "get", "getOrDefault",
116+
"merge", "putIfAbsent", "remove", "replace", "values"])
117+
or
118+
// java.util.Collection
119+
m.(CollectionMethod).hasName(["parallelStream", "stream", "toArray"])
103120
or
104-
m.(MapMethod).hasName("entrySet")
121+
// java.util.List
122+
m.(CollectionMethod).hasName(["get", "listIterator", "set", "subList"])
105123
or
106-
m.(MapMethod).hasName("get")
124+
m.(CollectionMethod).hasName("remove") and
125+
(m.getNumberOfParameters() = 0 or m.getParameterType(0).(PrimitiveType).hasName("int"))
107126
or
108-
m.(MapMethod).hasName("remove")
127+
// java.util.Vector
128+
m.(CollectionMethod).hasName(["elementAt", "elements", "firstElement", "lastElement"])
109129
or
110-
m.(MapMethod).hasName("values")
130+
// java.util.Stack
131+
m.(CollectionMethod).hasName(["peek", "pop", "push"])
111132
or
112-
m.(CollectionMethod).hasName("toArray")
133+
// java.util.Queue
134+
m.(CollectionMethod).hasName(["element", /*"peek", "remove"*/ "poll"])
113135
or
114-
m.(CollectionMethod).hasName("get")
136+
// java.util.DeQueue
137+
m
138+
.(CollectionMethod)
139+
.hasName(["getFirst", "getLast", "peekFirst", "peekLast", "pollFirst", "pollLast",
140+
"removeFirst", "removeLast"])
115141
or
116-
m.(CollectionMethod).hasName("remove") and m.getParameterType(0).(PrimitiveType).hasName("int")
142+
// java.util.concurrent.BlockingQueue
143+
m.(CollectionMethod).hasName("take")
117144
or
118-
m.(CollectionMethod).hasName("remove") and m.getNumberOfParameters() = 0
145+
// java.util.concurrent.BlockingDeque
146+
m.(CollectionMethod).hasName(["takeFirst", "takeLast"])
119147
or
120-
m.(CollectionMethod).hasName("subList")
148+
// java.util.SortedSet
149+
m.(CollectionMethod).hasName(["first", "headSet", "last", "subSet", "tailSet"])
121150
or
122-
m.(CollectionMethod).hasName("firstElement")
151+
// java.util.NavigableSet
152+
m
153+
.(CollectionMethod)
154+
.hasName(["ceiling", "descendingIterator", "descendingSet", "floor", "higher", "lower"])
123155
or
124-
m.(CollectionMethod).hasName("lastElement")
156+
//java.util.SortedMap
157+
m.(MapMethod).hasName(["headMap", "subMap", "tailMap"])
125158
or
126-
m.(CollectionMethod).hasName("poll")
159+
//java.util.NavigableMap
160+
m
161+
.(MapMethod)
162+
.hasName(["ceilingEntry", "descendingMap", "firstEntry", "floorEntry", "higherEntry",
163+
"lastEntry", "lowerEntry", "pollFirstEntry", "pollLastEntry"])
127164
or
128-
m.(CollectionMethod).hasName("peek")
165+
//java.util.Dictionary
166+
m
167+
.getDeclaringType()
168+
.getSourceDeclaration()
169+
.getASourceSupertype*()
170+
.hasQualifiedName("java.util", "Dictionary") and
171+
m.hasName(["elements", "get", "put", "remove"])
129172
or
130-
m.(CollectionMethod).hasName("element")
173+
// java.util.concurrent.ConcurrentHashMap
174+
m.(MapMethod).hasName(["search", "searchEntries", "searchValues"])
131175
}
132176

133177
private predicate qualifierToMethodStep(Expr tracked, MethodAccess sink) {

0 commit comments

Comments
 (0)