Have a more descriptive error message when infinite recusion happens (#26043)
Closes #21151 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
parent
8e8ff33b1f
commit
3cdc69ddbb
2 changed files with 12 additions and 2 deletions
|
@ -238,7 +238,11 @@ public final class StringPropertyReplacer
|
|||
buffer.append(string.substring(start, chars.length));
|
||||
|
||||
if (buffer.indexOf("${") != -1) {
|
||||
try {
|
||||
return replaceProperties(buffer.toString(), resolver);
|
||||
} catch (StackOverflowError ex) {
|
||||
throw new IllegalStateException("Infinite recursion happening when replacing properties on '" + buffer + "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.keycloak.common.util;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -59,6 +58,13 @@ public class StringPropertyReplacerTest {
|
|||
Assert.assertEquals("foo-val6", StringPropertyReplacer.replaceProperties("foo-${prop6,prop7:def}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStackOverflow() {
|
||||
System.setProperty("prop", "${prop}");
|
||||
IllegalStateException ise = Assert.assertThrows(IllegalStateException.class, () -> StringPropertyReplacer.replaceProperties("${prop}"));
|
||||
Assert.assertEquals("Infinite recursion happening when replacing properties on '${prop}'", ise.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnvironmentVariables() throws NoSuchAlgorithmException {
|
||||
Map<String, String> env = System.getenv();
|
||||
|
|
Loading…
Reference in a new issue