git » spf » commit cb8e8c3

Consolidate resolution limit checks

author Alberto Bertogli
2018-03-18 10:47:14 UTC
committer Alberto Bertogli
2018-03-18 13:16:26 UTC
parent 51c5931533a7eb50179c7ecfa022c9a34382b4e7

Consolidate resolution limit checks

We want limit each high level query to 10 resolutions, as per RFC.
Currently we check for this limit twice, but one of those checks
is redundant. This patch removes it.

spf.go +4 -6

diff --git a/spf.go b/spf.go
index 8183f86..029044c 100644
--- a/spf.go
+++ b/spf.go
@@ -105,13 +105,7 @@ type resolution struct {
 }
 
 func (r *resolution) Check(domain string) (Result, error) {
-	// Limit the number of resolutions to 10
-	// https://tools.ietf.org/html/rfc7208#section-4.6.4
-	if r.count > 10 {
-		return PermError, fmt.Errorf("lookup limit reached")
-	}
 	r.count++
-
 	txt, err := getDNSRecord(domain)
 	if err != nil {
 		if isTemporary(err) {
@@ -146,9 +140,13 @@ func (r *resolution) Check(domain string) (Result, error) {
 		if strings.HasPrefix(field, "v=") {
 			continue
 		}
+
+		// Limit the number of resolutions to 10
+		// https://tools.ietf.org/html/rfc7208#section-4.6.4
 		if r.count > 10 {
 			return PermError, fmt.Errorf("lookup limit reached")
 		}
+
 		if strings.Contains(field, "%") {
 			return Neutral, fmt.Errorf("macros not supported")
 		}