Skip to content

Commit 14623c6

Browse files
author
Valerie Peng
committed
8292739: Invalid legacy entries may be returned by Provider.getServices() call
Reviewed-by: weijun
1 parent 568be58 commit 14623c6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/java.base/share/classes/java/security/Provider.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,13 @@ public Set<Service> getServices() {
13211321
set.addAll(serviceMap.values());
13221322
}
13231323
if (!legacyMap.isEmpty()) {
1324-
set.addAll(legacyMap.values());
1324+
legacyMap.entrySet().forEach(entry -> {
1325+
if (!entry.getValue().isValid()) {
1326+
legacyMap.remove(entry.getKey(), entry.getValue());
1327+
} else {
1328+
set.add(entry.getValue());
1329+
}
1330+
});
13251331
}
13261332
serviceSet = Collections.unmodifiableSet(set);
13271333
servicesChanged = false;

test/jdk/java/security/Provider/CaseSensitiveServices.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 5097015 8130181 8279222
26+
* @bug 5097015 8130181 8279222 8292739
2727
* @summary make sure we correctly treat Provider string entries as case insensitive
2828
* @author Andreas Sterbenz
2929
*/
@@ -42,15 +42,23 @@ public class CaseSensitiveServices extends Provider {
4242
put("MESSAGEDIGEST.BAZ", "com.Baz");
4343
// reassign the DEF alias to algorithm Bar
4444
put("ALg.aliaS.MESSAGEdigest.DEF", "Bar");
45+
// invalid entry since it misses the corresponding impl class info
46+
// e.g. put("MessageDigest.Invalid", "implClass");
47+
put("MessageDigest.Invalid xYz", "aBc");
4548
}
4649

4750
public static void main(String[] args) throws Exception {
4851
Provider p = new CaseSensitiveServices();
49-
System.out.println(p.getServices());
52+
53+
System.out.println("Services: " + p.getServices());
54+
5055
if (p.getServices().size() != 3) {
5156
throw new Exception("services.size() should be 3");
5257
}
5358

59+
if (p.getService("MessageDigest", "Invalid") != null) {
60+
throw new Exception("Invalid service returned");
61+
}
5462
Service s = testService(p, "MessageDigest", "fOO");
5563
String val = s.getAttribute("Xyz");
5664
if ("aBc".equals(val) == false) {
@@ -70,7 +78,8 @@ public static void main(String[] args) throws Exception {
7078
System.out.println("OK");
7179
}
7280

73-
private static Service testService(Provider p, String type, String alg) throws Exception {
81+
private static Service testService(Provider p, String type, String alg)
82+
throws Exception {
7483
System.out.println("Getting " + type + "." + alg + "...");
7584
Service s = p.getService(type, alg);
7685
System.out.println(s);

0 commit comments

Comments
 (0)