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

chibenwa pushed a commit to branch fuzz-9
in repository https://gitbox.apache.org/repos/asf/james-jspf.git

commit 4403bcbef121c4307f2cd4274e92a3bd74664bd0
Author: Benoit TELLIER <[email protected]>
AuthorDate: Wed Nov 18 23:08:54 2026 +0100

    [FIX] MacroExpand: use constant patterns for macro transformers
    
    The digit, reverse and delimiter patterns were compiled into a shared
    instance field on each call. MacroExpand is shared by all checks of an
    SPF instance, so concurrent checks could read each other's pattern.
    Use static final patterns with local matchers instead.
---
 .../main/java/org/apache/james/jspf/core/MacroExpand.java | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java 
b/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
index 4d08e9a..2074ccd 100644
--- a/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
+++ b/resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java
@@ -52,7 +52,11 @@ public class MacroExpand {
 
     private Pattern macroLettersExpPattern;
 
-    private Pattern cellPattern;
+    private static final Pattern DIGITS_PATTERN = Pattern.compile("\\d+");
+
+    private static final Pattern REVERSE_PATTERN = Pattern.compile("r");
+
+    private static final Pattern DELIMITERS_PATTERN = 
Pattern.compile("[\\.\\-\\+\\,\\/\\_\\=]+");
 
     private DNSService dnsProbe;
 
@@ -440,8 +444,7 @@ public class MacroExpand {
         }
 
         // Find number of domains to use
-        cellPattern = Pattern.compile("\\d+");
-        cellMatcher = cellPattern.matcher(replaceValue);
+        cellMatcher = DIGITS_PATTERN.matcher(replaceValue);
         while (cellMatcher.find()) {
             domainNumber = cellMatcher.group();
             if (parseDigitTransformer(domainNumber) == 0) {
@@ -450,15 +453,13 @@ public class MacroExpand {
             }
         }
         // find if reversed
-        cellPattern = Pattern.compile("r");
-        cellMatcher = cellPattern.matcher(replaceValue);
+        cellMatcher = REVERSE_PATTERN.matcher(replaceValue);
         while (cellMatcher.find()) {
             isReversed = true;
         }
 
         // find delimeters
-        cellPattern = Pattern.compile("[\\.\\-\\+\\,\\/\\_\\=]+");
-        cellMatcher = cellPattern.matcher(replaceValue);
+        cellMatcher = DELIMITERS_PATTERN.matcher(replaceValue);
         while (cellMatcher.find()) {
             delimeters = cellMatcher.group();
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to