From fc984941eeaaa35ef9a04722ffcda8e8b5076243 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 1 Nov 2017 09:34:40 +0000 Subject: [PATCH] nflog: Fix Log() crash when gossip is nil (#1064) --- nflog/nflog.go | 8 +++++--- nflog/nflog_test.go | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nflog/nflog.go b/nflog/nflog.go index 2742a1f6..4cbf121d 100644 --- a/nflog/nflog.go +++ b/nflog/nflog.go @@ -360,9 +360,11 @@ func (l *nlog) Log(r *pb.Receiver, gkey string, firingAlerts, resolvedAlerts []u }, ExpiresAt: now.Add(l.retention), } - l.gossip.GossipBroadcast(gossipData{ - key: e, - }) + if l.gossip != nil { + l.gossip.GossipBroadcast(gossipData{ + key: e, + }) + } l.st[key] = e return nil diff --git a/nflog/nflog_test.go b/nflog/nflog_test.go index c7a8f0ab..abe8dfa4 100644 --- a/nflog/nflog_test.go +++ b/nflog/nflog_test.go @@ -264,3 +264,12 @@ func TestGossipDataCoding(t *testing.T) { require.Equal(t, in, out, "decoded data doesn't match encoded data") } } + +func TestNilGossipDoesNotCrash(t *testing.T) { + nl, err := New() + if err != nil { + require.NoError(t, err, "constructing nflog failed") + } + err = nl.Log(&pb.Receiver{}, "key", []uint64{}, []uint64{}) + require.NoError(t, err, "logging notification failed") +}