You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fs...@apache.org on 2020/06/26 14:58:57 UTC

[tomcat] branch pr309-recursion created (now 7f1b56e)

This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a change to branch pr309-recursion
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


      at 7f1b56e  Use method local counter for recurstion

This branch includes the following new commits:

     new 4f1ae64  Allow recursive substitution of properties.
     new 57e83d7  Add a iterationCount limited to 20 to prevent StackOverflowError.
     new 7f1b56e  Use method local counter for recurstion

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/03: Add a iterationCount limited to 20 to prevent StackOverflowError.

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch pr309-recursion
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 57e83d7c9eaa784d3af54fa57de100c99515f1bc
Author: Jean-Frederic Clere <jf...@gmail.com>
AuthorDate: Fri Jun 26 15:18:30 2020 +0200

    Add a iterationCount limited to 20 to prevent StackOverflowError.
---
 java/org/apache/tomcat/util/IntrospectionUtils.java | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/IntrospectionUtils.java b/java/org/apache/tomcat/util/IntrospectionUtils.java
index 977d33a..17fd47e 100644
--- a/java/org/apache/tomcat/util/IntrospectionUtils.java
+++ b/java/org/apache/tomcat/util/IntrospectionUtils.java
@@ -34,6 +34,7 @@ public final class IntrospectionUtils {
 
     private static final Log log = LogFactory.getLog(IntrospectionUtils.class);
     private static final StringManager sm = StringManager.getManager(IntrospectionUtils.class);
+    private static int iterationCount = 0;
 
     /**
      * Find a method with the right name If found, call the method ( if param is
@@ -340,7 +341,13 @@ public final class IntrospectionUtils {
             return value;
         if (log.isDebugEnabled())
             log.debug("IntrospectionUtils.replaceProperties iter on: " + newval);
-        return replaceProperties(newval, staticProp, dynamicProp, classLoader);
+        iterationCount++;
+        if (iterationCount <20)
+            newval = replaceProperties(newval, staticProp, dynamicProp, classLoader);
+        else
+            log.warn("System property failed to update and remains [" + newval + "]");
+        iterationCount--;
+        return newval;
     }
 
     private static String getProperty(String name, Hashtable<Object, Object> staticProp,


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 03/03: Use method local counter for recurstion

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch pr309-recursion
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 7f1b56e587693bb8f7755c972fbac493101c53c8
Author: Felix Schumacher <fs...@apache.org>
AuthorDate: Fri Jun 26 16:58:25 2020 +0200

    Use method local counter for recurstion
---
 java/org/apache/tomcat/util/IntrospectionUtils.java   | 19 +++++++++++--------
 .../apache/tomcat/util/TestIntrospectionUtils.java    |  7 +++++++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/tomcat/util/IntrospectionUtils.java b/java/org/apache/tomcat/util/IntrospectionUtils.java
index 17fd47e..08e0cbd 100644
--- a/java/org/apache/tomcat/util/IntrospectionUtils.java
+++ b/java/org/apache/tomcat/util/IntrospectionUtils.java
@@ -34,7 +34,7 @@ public final class IntrospectionUtils {
 
     private static final Log log = LogFactory.getLog(IntrospectionUtils.class);
     private static final StringManager sm = StringManager.getManager(IntrospectionUtils.class);
-    private static int iterationCount = 0;
+    private static final int MAX_RECURSION = 20;
 
     /**
      * Find a method with the right name If found, call the method ( if param is
@@ -286,7 +286,16 @@ public final class IntrospectionUtils {
     public static String replaceProperties(String value,
             Hashtable<Object,Object> staticProp, PropertySource dynamicProp[],
             ClassLoader classLoader) {
+        return replaceProperties(value, staticProp, dynamicProp, classLoader, 0);
+    }
 
+    private static String replaceProperties(String value,
+            Hashtable<Object,Object> staticProp, PropertySource dynamicProp[],
+            ClassLoader classLoader, int iterationCount) {
+        if (iterationCount >= MAX_RECURSION) {
+            log.warn("System property failed to update and remains [" + value + "]");
+            return value;
+        }
         if (value.indexOf('$') < 0) {
             return value;
         }
@@ -341,13 +350,7 @@ public final class IntrospectionUtils {
             return value;
         if (log.isDebugEnabled())
             log.debug("IntrospectionUtils.replaceProperties iter on: " + newval);
-        iterationCount++;
-        if (iterationCount <20)
-            newval = replaceProperties(newval, staticProp, dynamicProp, classLoader);
-        else
-            log.warn("System property failed to update and remains [" + newval + "]");
-        iterationCount--;
-        return newval;
+        return replaceProperties(newval, staticProp, dynamicProp, classLoader, iterationCount + 1);
     }
 
     private static String getProperty(String name, Hashtable<Object, Object> staticProp,
diff --git a/test/org/apache/tomcat/util/TestIntrospectionUtils.java b/test/org/apache/tomcat/util/TestIntrospectionUtils.java
index ed9fe39..981db4b 100644
--- a/test/org/apache/tomcat/util/TestIntrospectionUtils.java
+++ b/test/org/apache/tomcat/util/TestIntrospectionUtils.java
@@ -112,6 +112,13 @@ public class TestIntrospectionUtils {
                 StandardContext.class, "com.example.Other"));
     }
 
+    @Test
+    public void testReplacePropertiesRecursive() {
+        Properties properties = new Properties();
+        properties.put("replaceMe", "x${replaceMe}");
+        Assert.assertEquals("xxxxxxxxxxxxxxxxxxxx${replaceMe}",
+                IntrospectionUtils.replaceProperties("${replaceMe}", properties, null, null));
+    }
 
     @Test
     public void testReplaceProperties() {


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/03: Allow recursive substitution of properties.

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch pr309-recursion
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 4f1ae64882486eeb0b60f9daf13daeca5df6b7c9
Author: Jean-Frederic Clere <jf...@gmail.com>
AuthorDate: Fri Jun 26 09:50:09 2020 +0200

    Allow recursive substitution of properties.
---
 java/org/apache/tomcat/util/IntrospectionUtils.java | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/IntrospectionUtils.java b/java/org/apache/tomcat/util/IntrospectionUtils.java
index 78ab66f..977d33a 100644
--- a/java/org/apache/tomcat/util/IntrospectionUtils.java
+++ b/java/org/apache/tomcat/util/IntrospectionUtils.java
@@ -332,7 +332,15 @@ public final class IntrospectionUtils {
         }
         if (prev < value.length())
             sb.append(value.substring(prev));
-        return sb.toString();
+        String newval = sb.toString();
+        if (newval.indexOf('$') < 0) {
+            return newval;
+        }
+        if (newval.equals(value))
+            return value;
+        if (log.isDebugEnabled())
+            log.debug("IntrospectionUtils.replaceProperties iter on: " + newval);
+        return replaceProperties(newval, staticProp, dynamicProp, classLoader);
     }
 
     private static String getProperty(String name, Hashtable<Object, Object> staticProp,


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org