Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugin/auto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ are used.
used to extract the origin. **ORIGIN_TEMPLATE** will be used as a template for the origin. Strings
like `{<number>}` are replaced with the respective matches in the file name, e.g. `{1}` is the
first match, `{2}` is the second. The default is: `db\.(.*) {1}` i.e. from a file with the
name `db.example.com`, the extracted origin will be `example.com`.
name `db.example.com`, the extracted origin will be `example.com`. **REGEXP** must not be longer
than 10000 characters.
* `reload` interval to perform reloads of zones if SOA version changes and zonefiles. It specifies how often CoreDNS should scan the directory to watch for file removal and addition. Default is one minute.
Value of `0` means to not scan for changes and reload. eg. `30s` checks zonefile every 30 seconds
and reloads zone when serial changes.
Expand Down
5 changes: 5 additions & 0 deletions plugin/auto/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

var log = clog.NewWithPlugin("auto")

const maxRegexpLen = 10000

func init() { plugin.Register("auto", setup) }

func setup(c *caddy.Controller) error {
Expand Down Expand Up @@ -126,6 +128,9 @@ func autoParse(c *caddy.Controller) (Auto, error) {

// regexp template
if c.NextArg() {
if len(c.Val()) > maxRegexpLen {
return a, c.Errf("regexp too large")
}
a.re, err = regexp.Compile(c.Val())
if err != nil {
return a, err
Expand Down
17 changes: 17 additions & 0 deletions plugin/auto/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auto

import (
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -205,3 +206,19 @@ func TestSetupReload(t *testing.T) {
})
}
}

func TestAutoParseLargeRegex(t *testing.T) {
largeRegex := strings.Repeat("a", maxRegexpLen+1)
config := fmt.Sprintf(`auto {
directory /tmp %s {1}
}`, largeRegex)

c := caddy.NewTestController("dns", config)
_, err := autoParse(c)
if err == nil {
t.Fatal("Expected error for large regex, got nil")
}
if !strings.Contains(err.Error(), "regexp too large") {
t.Errorf("Expected 'regexp too large' error, got: %v", err)
}
}