mirror of
https://github.com/coredns/coredns.git
synced 2026-09-03 02:27:06 -04:00
plugin/hosts: don't drop entries after an over-long line (#8496)
bufio.Scanner stops at the first line longer than its 64KiB default buffer and reports bufio.ErrTooLong from Err(). parse() never checked Err(), so that line and every entry after it were dropped silently: the hosts file simply looked shorter than it is, with nothing in the log. Raise the scanner's limit to 1MiB (the scanner still grows its buffer lazily, so nothing is preallocated up front) and log an error if the scan does stop early, so the truncation is at least visible. Signed-off-by: Paco Cartones <pacocartones@users.noreply.github.com> Co-authored-by: Paco Cartones <pacocartones@users.noreply.github.com>
This commit is contained in:
@@ -290,3 +290,19 @@ func TestLookupStaticHostReloadRace(t *testing.T) {
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestParseLineLongerThanDefaultScanBuffer(t *testing.T) {
|
||||
// A line longer than bufio.Scanner's default 64KiB buffer must not stop
|
||||
// the scan: the entries that follow it still have to be parsed.
|
||||
long := strings.Repeat("a", 70*1024)
|
||||
h := testHostsfile("127.0.0.1 before.example.org\n" +
|
||||
"127.0.0.2 " + long + ".example.org\n" +
|
||||
"127.0.0.3 after.example.org\n")
|
||||
|
||||
if addrs := h.LookupStaticHostV4("before.example.org."); len(addrs) != 1 || addrs[0].String() != "127.0.0.1" {
|
||||
t.Errorf("LookupStaticHostV4(before.example.org.) = %v, want [127.0.0.1]", addrs)
|
||||
}
|
||||
if addrs := h.LookupStaticHostV4("after.example.org."); len(addrs) != 1 || addrs[0].String() != "127.0.0.3" {
|
||||
t.Errorf("LookupStaticHostV4(after.example.org.) = %v, want [127.0.0.3]", addrs)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user