Skip to content

Commit 9b7437f

Browse files
chantramiekg
authored andcommitted
[zone parser] disallow nested $GENERATE directive (#1033)
While the range number of GENERATE is now limited, one can pass a line with 2 $GENERATE directive that will exponentially increase the time spent generating RRs. Limit to only one per line. Fixes #1020
1 parent 4d4363a commit 9b7437f

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

generate.go

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (zp *ZoneParser) generate(l lex) (RR, bool) {
8585
}
8686
zp.sub = NewZoneParser(r, zp.origin, zp.file)
8787
zp.sub.includeDepth, zp.sub.includeAllowed = zp.includeDepth, zp.includeAllowed
88+
zp.sub.generateDisallowed = true
8889
zp.sub.SetDefaultTTL(defaultTtl)
8990
return zp.subNext()
9091
}

generate_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ $GENERATE 0-1/0 dhcp-${0,4,d} A 10.0.0.$
6161
`, true},
6262
{`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
6363
$GENERATE 0-1 $$INCLUDE ` + tmpdir + string(filepath.Separator) + `${0,4,d}.conf
64+
`, false},
65+
{`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
66+
$GENERATE 0-1 dhcp-${0,4,d} A 10.0.0.$
67+
$GENERATE 0-2 dhcp-${0,4,d} A 10.1.0.$
6468
`, false},
6569
}
6670
Outer:
@@ -214,6 +218,7 @@ func TestCrasherString(t *testing.T) {
214218
{"$GENERATE 0-5414137360", "bad range in $GENERATE"},
215219
{"$GENERATE 11522-3668518066406258", "bad range in $GENERATE"},
216220
{"$GENERATE 0-200\"(;00000000000000\n$$GENERATE 0-0", "dns: garbage after $GENERATE range: \"\\\"\" at line: 1:16"},
221+
{"$GENERATE 6-2048 $$GENERATE 6-036160 $$$$ORIGIN \\$", `dns: nested $GENERATE directive not allowed: "6-036160" at line: 1:19`},
217222
}
218223
for _, tc := range tests {
219224
t.Run(tc.in, func(t *testing.T) {

scan.go

+4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ type ZoneParser struct {
248248
includeDepth uint8
249249

250250
includeAllowed bool
251+
generateDisallowed bool
251252
}
252253

253254
// NewZoneParser returns an RFC 1035 style zonefile parser that reads
@@ -547,6 +548,9 @@ func (zp *ZoneParser) Next() (RR, bool) {
547548

548549
st = zExpectDirGenerate
549550
case zExpectDirGenerate:
551+
if zp.generateDisallowed {
552+
return zp.setParseError("nested $GENERATE directive not allowed", l)
553+
}
550554
if l.value != zString {
551555
return zp.setParseError("expecting $GENERATE value, not this...", l)
552556
}

0 commit comments

Comments
 (0)