From 2cca3ec1f7ba9093b62dd799d171001ce876b790 Mon Sep 17 00:00:00 2001 From: Peter Schultz Date: Mon, 18 Nov 2019 10:20:46 +0100 Subject: [PATCH] fix nil-pointer dereference in detailed config log Closes #719. Signed-off-by: Peter Schultz --- CHANGELOG.md | 6 ++++++ route/table.go | 2 +- route/table_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92b3f8315..2c491d5dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### Unreleased + +#### Bug Fixes + +* [Issue #719](https://github.com/fabiolb/fabio/issues/719): Fix detailed config log + ### [v1.5.12](https://github.com/fabiolb/fabio/releases/tag/v1.5.12) - 11 Oct 2019 #### Breaking Changes diff --git a/route/table.go b/route/table.go index 67a5ca603..fa8dd78fe 100644 --- a/route/table.go +++ b/route/table.go @@ -501,7 +501,7 @@ func (t Table) String() string { // Dump returns the routing table as a detailed func (t Table) Dump() string { - var w *bytes.Buffer + w := new(bytes.Buffer) hosts := []string{} for k := range t { diff --git a/route/table_test.go b/route/table_test.go index 86b260927..c5ca2e246 100644 --- a/route/table_test.go +++ b/route/table_test.go @@ -731,3 +731,32 @@ func TestNewTableCustom(t *testing.T) { t.FailNow() } } + +func TestTable_Dump(t *testing.T) { + s := ` + route add svc / http://foo.com:800 + route add svc /foo http://foo.com:900 + route add svc abc.com/ http://foo.com:1000 + ` + + tbl, err := NewTable(bytes.NewBufferString(s)) + if err != nil { + t.Fatal(err) + } + + want := `+-- host= +| |-- path=/foo +| | +-- addr=foo.com:900 weight 1.00 slots 1/1 +| +-- path=/ +| +-- addr=foo.com:800 weight 1.00 slots 1/1 ++-- host=abc.com + +-- path=/ + +-- addr=foo.com:1000 weight 1.00 slots 1/1 +` + + got := tbl.Dump() + + if want != got { + t.Errorf("Unexpected Dump() output:\nwant:\n%s\ngot:\n%s\n", want, got) + } +}