8358549: O(n²) time complexity in java.security.Provider.parseLegacy() method

Reviewed-by: mullan, djelinski
This commit is contained in:
Mark Powers 2026-07-14 14:47:16 +00:00
parent feb944c6c9
commit f71c37bdb3
2 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1084,9 +1084,16 @@ public abstract class Provider extends Properties {
String stdAlg = attrString.substring(0, i).intern();
String attrName = attrString.substring(i + 1);
// kill additional spaces
while (attrName.startsWith(" ")) {
attrName = attrName.substring(1);
int pos = 0;
for (; pos < attrName.length(); pos++) {
if (attrName.charAt(pos) != ' ') {
break;
}
}
if (pos > 0) {
attrName = attrName.substring(pos);
}
attrName = attrName.intern();
ServiceKey stdKey = new ServiceKey(type, stdAlg, true);
Service stdService = legacyMap.get(stdKey);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/**
* @test
* @bug 4911081 8130181
* @bug 4911081 8130181 8358549
* @library /test/lib
* @summary verify that Provider.Service.supportsParameter() works
* @author Andreas Sterbenz
@ -112,7 +112,9 @@ public class SupportsParameter {
put("Signature.DSA0", "foo.DSA0");
put("Signature.DSA", "foo.DSA");
put("Signature.DSA SupportedKeyClasses",
// Extra spaces between "Signature.DSA" and "SupportedKeyClasses"
// are used to verify that whitespace is trimmed.
put("Signature.DSA SupportedKeyClasses",
"java.security.interfaces.DSAPublicKey" +
"|java.security.interfaces.DSAPrivateKey");