Skip to content

Commit e20bd01

Browse files
committedJan 24, 2025
8344361: Restore null return for invalid services from legacy providers
Reviewed-by: valeriep
1 parent 5a0bdd0 commit e20bd01

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
 

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

+1
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ public Service getService(String type, String algorithm) {
11471147
s = legacyMap.get(key);
11481148
if (s != null && !s.isValid()) {
11491149
legacyMap.remove(key, s);
1150+
return null;
11501151
}
11511152
}
11521153

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8344361
27+
* @summary Restore null return for invalid services
28+
*/
29+
30+
import java.security.Provider;
31+
32+
public class InvalidServiceTest {
33+
34+
public static void main(String[] args) throws Exception {
35+
Provider p1 = new LProvider("LegacyFormat");
36+
// this returns a service with null class name. Helps exercise the code path
37+
Provider.Service s1 = p1.getService("MessageDigest", "SHA-1");
38+
if (s1 != null)
39+
throw new RuntimeException("expecting null service");
40+
}
41+
42+
private static class LProvider extends Provider {
43+
LProvider(String name) {
44+
super(name, "1.0", null);
45+
put("Signature.MD5withRSA", "com.foo.Sig");
46+
put("MessageDigest.SHA-1 ImplementedIn", "Software");
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)
Please sign in to comment.