author | Alberto Bertogli
<albertito@blitiri.com.ar> 2023-09-23 19:31:45 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2023-09-24 08:32:32 UTC |
parent | 8bbb6118e50cde3451a92dc69f2d5888900083aa |
internal/aliases/aliases.go | +5 | -5 |
internal/aliases/aliases_test.go | +5 | -1 |
diff --git a/internal/aliases/aliases.go b/internal/aliases/aliases.go index 20b556d..e2be600 100644 --- a/internal/aliases/aliases.go +++ b/internal/aliases/aliases.go @@ -303,7 +303,7 @@ func (v *Resolver) AddAliasesFile(domain, path string) error { v.domains[domain] = true v.mu.Unlock() - aliases, err := parseFile(domain, path) + aliases, err := v.parseFile(domain, path) if os.IsNotExist(err) { return nil } @@ -333,7 +333,7 @@ func (v *Resolver) Reload() error { for domain, paths := range v.files { for _, path := range paths { - aliases, err := parseFile(domain, path) + aliases, err := v.parseFile(domain, path) if os.IsNotExist(err) { continue } @@ -355,21 +355,21 @@ func (v *Resolver) Reload() error { return nil } -func parseFile(domain, path string) (map[string][]Recipient, error) { +func (v *Resolver) parseFile(domain, path string) (map[string][]Recipient, error) { f, err := os.Open(path) if err != nil { return nil, err } defer f.Close() - aliases, err := parseReader(domain, f) + aliases, err := v.parseReader(domain, f) if err != nil { return nil, fmt.Errorf("reading %q: %v", path, err) } return aliases, nil } -func parseReader(domain string, r io.Reader) (map[string][]Recipient, error) { +func (v *Resolver) parseReader(domain string, r io.Reader) (map[string][]Recipient, error) { aliases := map[string][]Recipient{} scanner := bufio.NewScanner(r) diff --git a/internal/aliases/aliases_test.go b/internal/aliases/aliases_test.go index a6b44be..15569ab 100644 --- a/internal/aliases/aliases_test.go +++ b/internal/aliases/aliases_test.go @@ -504,7 +504,11 @@ func TestHookError(t *testing.T) { // Fuzz testing for the parser. func FuzzReader(f *testing.F) { + resolver := NewResolver(allUsersExist) + resolver.AddDomain("domain") + resolver.DropChars = "." + resolver.SuffixSep = "-+" f.Fuzz(func(t *testing.T, data []byte) { - parseReader("domain", bytes.NewReader(data)) + resolver.parseReader("domain", bytes.NewReader(data)) }) }