This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-jspf.git
commit e35b73ad0b23e39a8eb9e3fdaeac21f1abc94796 Author: Quan Tran <[email protected]> AuthorDate: Fri Oct 30 16:33:50 2026 +0700 [FIX] a/mx mechanisms: an overflowing dual CIDR length is a permerror As for ip4:, the regex accepts any number of digits as the CIDR lengths, so a/4294967296 or mx//99999999999 made Integer.parseInt throw NumberFormatException out of the parser: the check ended as neutral instead of permerror. Reject a length of more than 3 digits before parsing it, as a/33 is: a record out of the grammar of RFC 7208 5.6 is a permerror (4.6). --- .../main/java/org/apache/james/jspf/terms/AMechanism.java | 7 +++++++ .../java/org/apache/james/jspf/SPFExecutorBaseTest.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/resolver/src/main/java/org/apache/james/jspf/terms/AMechanism.java b/resolver/src/main/java/org/apache/james/jspf/terms/AMechanism.java index 68784ff..416a458 100644 --- a/resolver/src/main/java/org/apache/james/jspf/terms/AMechanism.java +++ b/resolver/src/main/java/org/apache/james/jspf/terms/AMechanism.java @@ -134,7 +134,11 @@ public class AMechanism extends GenericMechanism implements SPFCheckerDNSRespons */ public synchronized void config(Configuration params) throws PermErrorException { super.config(params); + // the regex accepts any number of digits: more than 3 are invalid, and could overflow an int if (params.groupCount() >= 2 && params.group(2) != null) { + if (params.group(2).length() > 3) { + throw new PermErrorException("Ivalid IP4 CIDR length"); + } ip4cidr = Integer.parseInt(params.group(2)); if (ip4cidr > 32) { throw new PermErrorException("Ivalid IP4 CIDR length"); @@ -143,6 +147,9 @@ public class AMechanism extends GenericMechanism implements SPFCheckerDNSRespons ip4cidr = 32; } if (params.groupCount() >= 3 && params.group(3) != null) { + if (params.group(3).length() > 3) { + throw new PermErrorException("Ivalid IP6 CIDR length"); + } ip6cidr = Integer.parseInt(params.group(3).toString()); if (ip6cidr > 128) { throw new PermErrorException("Ivalid IP6 CIDR length"); diff --git a/resolver/src/test/java/org/apache/james/jspf/SPFExecutorBaseTest.java b/resolver/src/test/java/org/apache/james/jspf/SPFExecutorBaseTest.java index f56e270..536025a 100644 --- a/resolver/src/test/java/org/apache/james/jspf/SPFExecutorBaseTest.java +++ b/resolver/src/test/java/org/apache/james/jspf/SPFExecutorBaseTest.java @@ -470,4 +470,18 @@ public abstract class SPFExecutorBaseTest { assertEquals(SPFErrorConstants.PERM_ERROR_CONV, result.getResult()); } + + @Test(timeout = 10000) + public void shouldReturnPermErrorOnAIp4CidrOverflowingAnInt() throws IOException { + SPFResult result = checkRecord("aIp4CidrOverflow.spfexecutor.fake", "v=spf1 a/4294967296 -all", "1.2.3.4"); + + assertEquals(SPFErrorConstants.PERM_ERROR_CONV, result.getResult()); + } + + @Test(timeout = 10000) + public void shouldReturnPermErrorOnMxIp6CidrOverflowingAnInt() throws IOException { + SPFResult result = checkRecord("mxIp6CidrOverflow.spfexecutor.fake", "v=spf1 mx//99999999999 -all", "1.2.3.4"); + + assertEquals(SPFErrorConstants.PERM_ERROR_CONV, result.getResult()); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
