1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

BUG: SPF split doesn't produce consistent output (#1865)

This commit is contained in:
Tom Limoncelli
2022-12-26 09:11:52 -05:00
committed by GitHub
parent 7654107614
commit bf0badf2f2

View File

@ -2,13 +2,26 @@ package normalize
import (
"fmt"
"sort"
"strconv"
"strings"
"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/spflib"
"golang.org/x/exp/constraints"
)
func sortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
keys := make([]K, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
return keys
}
// hasSpfRecords returns true if this record requests SPF unrolling.
func flattenSPFs(cfg *models.DNSConfig) []error {
var cache spflib.CachingResolver
@ -74,7 +87,9 @@ func flattenSPFs(cfg *models.DNSConfig) []error {
continue
}
recs := rec.TXTSplit(split+"."+domain.Name, overhead1, txtMaxSize)
for k, v := range recs {
for _, k := range sortedKeys(recs) {
v := recs[k]
if k == "@" {
txt.SetTargetTXTs(v)
} else {