mirror of
https://github.com/keycloak/keycloak.git
synced 2026-02-06 23:39:00 -06:00
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:
committed by
GitHub
parent
8e8ff33b1f
commit
3cdc69ddbb
@@ -238,7 +238,11 @@ public final class StringPropertyReplacer
|
||||
buffer.append(string.substring(start, chars.length));
|
||||
|
||||
if (buffer.indexOf("${") != -1) {
|
||||
return replaceProperties(buffer.toString(), resolver);
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user