Skip to content

Commit 8cf47f1

Browse files
committed
Model constructors of classes implementing MultivaluedMap
1 parent e0130a9 commit 8cf47f1

File tree

7 files changed

+453
-0
lines changed

7 files changed

+453
-0
lines changed

java/ql/src/semmle/code/java/frameworks/JaxWS.qll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,40 @@ private class MultivaluedMapModel extends SummaryModelCsv {
476476
}
477477
}
478478

479+
/**
480+
* Model AbstractMultivaluedMap, which implements MultivaluedMap.
481+
*/
482+
private class AbstractMultivaluedMapModel extends SummaryModelCsv {
483+
override predicate row(string row) {
484+
row =
485+
[
486+
"javax.ws.rs.core;AbstractMultivaluedMap;false;AbstractMultivaluedMap;;;MapKey of Argument[0];MapKey of Argument[-1];value",
487+
"javax.ws.rs.core;AbstractMultivaluedMap;false;AbstractMultivaluedMap;;;MapValue of Argument[0];MapValue of Argument[-1];value",
488+
"jakarta.ws.rs.core;AbstractMultivaluedMap;false;AbstractMultivaluedMap;;;MapKey of Argument[0];MapKey of Argument[-1];value",
489+
"jakarta.ws.rs.core;AbstractMultivaluedMap;false;AbstractMultivaluedMap;;;MapValue of Argument[0];MapValue of Argument[-1];value"
490+
]
491+
}
492+
}
493+
494+
/**
495+
* Model MultivaluedHashMap, which extends AbstractMultivaluedMap.
496+
*/
497+
private class MultivaluedHashMapModel extends SummaryModelCsv {
498+
override predicate row(string row) {
499+
row =
500+
[
501+
"javax.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(Map);;MapKey of Argument[0];MapKey of Argument[-1];value",
502+
"javax.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(Map);;MapValue of Argument[0];Element of MapValue of Argument[-1];value",
503+
"javax.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(MultivaluedMap);;MapKey of Argument[0];MapKey of Argument[-1];value",
504+
"javax.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(MultivaluedMap);;MapValue of Argument[0];MapValue of Argument[-1];value",
505+
"jakarta.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(Map);;MapKey of Argument[0];MapKey of Argument[-1];value",
506+
"jakarta.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(Map);;MapValue of Argument[0];Element of MapValue of Argument[-1];value",
507+
"jakarta.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(MultivaluedMap);;MapKey of Argument[0];MapKey of Argument[-1];value",
508+
"jakarta.ws.rs.core;MultivaluedHashMap;false;MultivaluedHashMap;(MultivaluedMap);;MapValue of Argument[0];MapValue of Argument[-1];value"
509+
]
510+
}
511+
}
512+
479513
/**
480514
* Model PathSegment, which wraps a path and its associated matrix parameters.
481515
*/

java/ql/test/library-tests/frameworks/JaxWs/JakartaRsFlow.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.Set;
10+
import jakarta.ws.rs.core.AbstractMultivaluedMap;
1011
import jakarta.ws.rs.core.CacheControl;
1112
import jakarta.ws.rs.core.Cookie;
1213
import jakarta.ws.rs.core.EntityTag;
@@ -15,6 +16,7 @@
1516
import jakarta.ws.rs.core.HttpHeaders;
1617
import jakarta.ws.rs.core.Link;
1718
import jakarta.ws.rs.core.MediaType;
19+
import jakarta.ws.rs.core.MultivaluedHashMap;
1820
import jakarta.ws.rs.core.MultivaluedMap;
1921
import jakarta.ws.rs.core.NewCookie;
2022
import jakarta.ws.rs.core.PathSegment;
@@ -149,6 +151,42 @@ void testMultivaluedMapputSingle(MultivaluedMap<String, String> mm1, Multivalued
149151
sink(mm2.get("key").get(0)); // $hasValueFlow
150152
}
151153

154+
class MyAbstractMultivaluedMapJak<K, V> extends AbstractMultivaluedMap<K, V> {
155+
public MyAbstractMultivaluedMapJak(Map<K, List<V>> map) {
156+
super(map);
157+
}
158+
}
159+
160+
void testAbstractMultivaluedMap(Map<String, List<String>> map1, Map<String, List<String>> map2, List<String> list) {
161+
map1.put(taint(), list);
162+
AbstractMultivaluedMap<String, String> amm1 = new MyAbstractMultivaluedMapJak<String, String>(map1);
163+
sink(amm1.keySet().iterator().next()); // $hasValueFlow
164+
165+
list.add(taint());
166+
map2.put("key", list);
167+
AbstractMultivaluedMap<String, String> amm2 = new MyAbstractMultivaluedMapJak<String, String>(map2);
168+
sink(amm2.get("key").get(0)); // $hasValueFlow
169+
}
170+
171+
void testMultivaluedHashMap(Map<String, String> map1, Map<String, String> map2,
172+
MultivaluedMap<String, String> mm1, MultivaluedMap<String, String> mm2) {
173+
map1.put(taint(), "value");
174+
MultivaluedHashMap<String, String> mhm1 = new MultivaluedHashMap<String, String>(map1);
175+
sink(mhm1.keySet().iterator().next()); // $hasValueFlow
176+
177+
map2.put("key", taint());
178+
MultivaluedHashMap<String, String> mhm2 = new MultivaluedHashMap<String, String>(map2);
179+
sink(mhm2.get("key").get(0)); // $hasValueFlow
180+
181+
mm1.add(taint(), "value");
182+
MultivaluedHashMap<String, String> mhm3 = new MultivaluedHashMap<String, String>(mm1);
183+
sink(mhm3.keySet().iterator().next()); // $hasValueFlow
184+
185+
mm2.add("key", taint());
186+
MultivaluedHashMap<String, String> mhm4 = new MultivaluedHashMap<String, String>(mm2);
187+
sink(mhm4.get("key").get(0)); // $hasValueFlow
188+
}
189+
152190
void testPathSegment(PathSegment ps1, PathSegment ps2) {
153191
sink(taint(ps1).getMatrixParameters()); // $hasTaintFlow
154192
sink(taint(ps2).getPath()); // $hasTaintFlow

java/ql/test/library-tests/frameworks/JaxWs/JaxRsFlow.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.Set;
10+
import javax.ws.rs.core.AbstractMultivaluedMap;
1011
import javax.ws.rs.core.CacheControl;
1112
import javax.ws.rs.core.Cookie;
1213
import javax.ws.rs.core.EntityTag;
@@ -15,6 +16,7 @@
1516
import javax.ws.rs.core.HttpHeaders;
1617
import javax.ws.rs.core.Link;
1718
import javax.ws.rs.core.MediaType;
19+
import javax.ws.rs.core.MultivaluedHashMap;
1820
import javax.ws.rs.core.MultivaluedMap;
1921
import javax.ws.rs.core.NewCookie;
2022
import javax.ws.rs.core.PathSegment;
@@ -149,6 +151,42 @@ void testMultivaluedMapputSingle(MultivaluedMap<String, String> mm1, Multivalued
149151
sink(mm2.get("key").get(0)); // $hasValueFlow
150152
}
151153

154+
class MyAbstractMultivaluedMap<K, V> extends AbstractMultivaluedMap<K, V> {
155+
public MyAbstractMultivaluedMap(Map<K, List<V>> map) {
156+
super(map);
157+
}
158+
}
159+
160+
void testAbstractMultivaluedMap(Map<String, List<String>> map1, Map<String, List<String>> map2, List<String> list) {
161+
map1.put(taint(), list);
162+
AbstractMultivaluedMap<String, String> amm1 = new MyAbstractMultivaluedMap<String, String>(map1);
163+
sink(amm1.keySet().iterator().next()); // $hasValueFlow
164+
165+
list.add(taint());
166+
map2.put("key", list);
167+
AbstractMultivaluedMap<String, String> amm2 = new MyAbstractMultivaluedMap<String, String>(map2);
168+
sink(amm2.get("key").get(0)); // $hasValueFlow
169+
}
170+
171+
void testMultivaluedHashMap(Map<String, String> map1, Map<String, String> map2,
172+
MultivaluedMap<String, String> mm1, MultivaluedMap<String, String> mm2) {
173+
map1.put(taint(), "value");
174+
MultivaluedHashMap<String, String> mhm1 = new MultivaluedHashMap<String, String>(map1);
175+
sink(mhm1.keySet().iterator().next()); // $hasValueFlow
176+
177+
map2.put("key", taint());
178+
MultivaluedHashMap<String, String> mhm2 = new MultivaluedHashMap<String, String>(map2);
179+
sink(mhm2.get("key").get(0)); // $hasValueFlow
180+
181+
mm1.add(taint(), "value");
182+
MultivaluedHashMap<String, String> mhm3 = new MultivaluedHashMap<String, String>(mm1);
183+
sink(mhm3.keySet().iterator().next()); // $hasValueFlow
184+
185+
mm2.add("key", taint());
186+
MultivaluedHashMap<String, String> mhm4 = new MultivaluedHashMap<String, String>(mm2);
187+
sink(mhm4.get("key").get(0)); // $hasValueFlow
188+
}
189+
152190
void testPathSegment(PathSegment ps1, PathSegment ps2) {
153191
sink(taint(ps1).getMatrixParameters()); // $hasTaintFlow
154192
sink(taint(ps2).getPath()); // $hasTaintFlow
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package javax.ws.rs.core;
18+
import java.util.Collection;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.Set;
22+
23+
public abstract class AbstractMultivaluedMap<K, V> implements MultivaluedMap<K, V> {
24+
public AbstractMultivaluedMap(Map<K, List<V>> store) {
25+
}
26+
27+
@Override
28+
public final void putSingle(K key, V value) {
29+
}
30+
31+
@Override
32+
public final void add(K key, V value) {
33+
}
34+
35+
@Override
36+
public final void addAll(K key, V... newValues) {
37+
}
38+
39+
@Override
40+
public final void addAll(K key, List<V> valueList) {
41+
}
42+
43+
@Override
44+
public final V getFirst(K key) {
45+
return null;
46+
}
47+
48+
@Override
49+
public final void addFirst(K key, V value) {
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return null;
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return 0;
60+
}
61+
62+
@Override
63+
public boolean equals(Object o) {
64+
return false;
65+
}
66+
67+
@Override
68+
public Collection<List<V>> values() {
69+
return null;
70+
}
71+
72+
@Override
73+
public int size() {
74+
return 0;
75+
}
76+
77+
@Override
78+
public List<V> remove(Object key) {
79+
return null;
80+
}
81+
82+
@Override
83+
public void putAll(Map<? extends K, ? extends List<V>> m) {
84+
}
85+
86+
@Override
87+
public List<V> put(K key, List<V> value) {
88+
return null;
89+
}
90+
91+
@Override
92+
public Set<K> keySet() {
93+
return null;
94+
}
95+
96+
@Override
97+
public boolean isEmpty() {
98+
return false;
99+
}
100+
101+
@Override
102+
public List<V> get(Object key) {
103+
return null;
104+
}
105+
106+
@Override
107+
public Set<Entry<K, List<V>>> entrySet() {
108+
return null;
109+
}
110+
111+
@Override
112+
public boolean containsValue(Object value) {
113+
return false;
114+
}
115+
116+
@Override
117+
public boolean containsKey(Object key) {
118+
return false;
119+
}
120+
121+
@Override
122+
public void clear() {
123+
}
124+
125+
@Override
126+
public boolean equalsIgnoreValueOrder(MultivaluedMap<K, V> omap) {
127+
return false;
128+
}
129+
130+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2011, 2017 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package javax.ws.rs.core;
18+
import java.io.Serializable;
19+
import java.util.HashMap;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
public class MultivaluedHashMap<K, V> extends AbstractMultivaluedMap<K, V> implements Serializable {
24+
// public MultivaluedHashMap() {
25+
// }
26+
27+
// public MultivaluedHashMap(int initialCapacity) {
28+
// }
29+
30+
// public MultivaluedHashMap(int initialCapacity, float loadFactor) {
31+
// }
32+
33+
public MultivaluedHashMap(MultivaluedMap<? extends K, ? extends V> map) {
34+
super(new HashMap<K, List<V>>());
35+
}
36+
37+
public MultivaluedHashMap(Map<? extends K, ? extends V> map) {
38+
super(new HashMap<K, List<V>>());
39+
}
40+
41+
}

0 commit comments

Comments
 (0)