This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-jspf.git
The following commit(s) were added to refs/heads/master by this push: new 0c85962 JSPF-111 NPE when setting SPFResult (#22) 0c85962 is described below commit 0c85962d626fa1e5e80ee219e49c518553797273 Author: Benoit TELLIER <btell...@linagora.com> AuthorDate: Wed Jul 10 09:27:17 2024 +0200 JSPF-111 NPE when setting SPFResult (#22) --- .../jspf/executor/AsynchronousSPFExecutor.java | 30 +++++++++++----- .../org/apache/james/jspf/SpfVerifierTest.java | 40 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java b/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java index 2aee4ce..56d2c8b 100644 --- a/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java +++ b/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java @@ -19,6 +19,8 @@ package org.apache.james.jspf.executor; +import java.util.ArrayList; + import org.apache.james.jspf.core.DNSLookupContinuation; import org.apache.james.jspf.core.DNSResponse; import org.apache.james.jspf.core.DNSService; @@ -33,6 +35,7 @@ import org.apache.james.jspf.core.exceptions.TempErrorException; import org.apache.james.jspf.core.exceptions.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.xbill.DNS.lookup.NoSuchRRSetException; /** * Synchronous implementation of SPFExecuter. All queries will get executed synchronously @@ -61,7 +64,7 @@ public class AsynchronousSPFExecutor implements SPFExecutor { DNSLookupContinuation cont = checker.checkSPF(session); handleCont(session, result, cont, checker); } catch (Exception e) { - handleError(session, checker, e); + handleError(session, e); result.setSPFResult(session); } } @@ -75,15 +78,23 @@ public class AsynchronousSPFExecutor implements SPFExecutor { DNSLookupContinuation dnsLookupContinuation = cont.getListener().onDNSResponse(new DNSResponse(results), session); handleCont(session, result, dnsLookupContinuation, checker); } catch (PermErrorException | NoneException | TempErrorException | NeutralException e) { - handleError(session, checker, e); + handleError(session, e); } }) .exceptionally(e -> { + if (e instanceof NoSuchRRSetException || e.getCause() instanceof NoSuchRRSetException) { + try { + DNSLookupContinuation dnsLookupContinuation = cont.getListener().onDNSResponse(new DNSResponse(new ArrayList<>()), session); + handleCont(session, result, dnsLookupContinuation, checker); + } catch (PermErrorException | NoneException | TempErrorException | NeutralException ex2) { + handleError(session, ex2); + } + } if (e instanceof TimeoutException) { - handleTimeout(session, checker, cont, (TimeoutException) e); + handleTimeout(cont, new DNSResponse((TimeoutException) e), session, result, checker); } if (e.getCause() instanceof TimeoutException) { - handleTimeout(session, checker, cont, (TimeoutException) e.getCause()); + handleTimeout(cont, new DNSResponse((TimeoutException) e.getCause()), session, result, checker); } result.setSPFResult(session); return null; @@ -93,17 +104,18 @@ public class AsynchronousSPFExecutor implements SPFExecutor { } } - private void handleTimeout(SPFSession session, SPFChecker finalChecker, DNSLookupContinuation cont, TimeoutException e) { + private void handleTimeout(DNSLookupContinuation cont, DNSResponse e, SPFSession session, FutureSPFResult result, SPFChecker checker) { try { - cont.getListener().onDNSResponse(new DNSResponse(e), session); + DNSLookupContinuation dnsLookupContinuation = cont.getListener().onDNSResponse(e, session); + handleCont(session, result, dnsLookupContinuation, checker); } catch (PermErrorException | NoneException | TempErrorException | NeutralException ex2) { - handleError(session, finalChecker, ex2); + handleError(session, ex2); } } - private void handleError(SPFSession session, SPFChecker checker, Exception e) { + private void handleError(SPFSession session, Exception e) { while (e != null) { - checker = session.popChecker(c -> c instanceof SPFCheckerExceptionCatcher); + SPFChecker checker = session.popChecker(c -> c instanceof SPFCheckerExceptionCatcher); if (checker == null) { // Error case not handled by JSPF. Throw to avoid infinite loop. See JSPF-110. throw new RuntimeException("SPFCheckerExceptionCatcher implementation not found, session: " + session, e); diff --git a/resolver/src/test/java/org/apache/james/jspf/SpfVerifierTest.java b/resolver/src/test/java/org/apache/james/jspf/SpfVerifierTest.java new file mode 100644 index 0000000..4effa0f --- /dev/null +++ b/resolver/src/test/java/org/apache/james/jspf/SpfVerifierTest.java @@ -0,0 +1,40 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.jspf; + +import org.junit.Test; +import org.apache.james.jspf.executor.SPFResult; +import org.apache.james.jspf.impl.DefaultSPF; +import org.apache.james.jspf.impl.SPF; + +public class SpfVerifierTest { + @Test + public void shouldHandleRecordNotFound() { + String ipAddress = "103.52.180.162"; + String hostName = "FMTA1-162.ncdelivery04.com"; + String from = "17191683732756478-181603-1-mxscout....@delivery.forumofsecrets.com"; + + final SPF spfChecker = new DefaultSPF(); + spfChecker.setUseBestGuess(true); + + SPFResult spfResult = spfChecker.checkSPF(ipAddress, from, hostName); + spfResult.getResult(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org