From 6c7d9daa94e3b49ffcdaef2933a375dfbdf03013 Mon Sep 17 00:00:00 2001 From: Patrick East Date: Tue, 12 May 2020 16:07:57 -0700 Subject: [PATCH] plugins: Fix panic with /health and envoy plugin If there was a nil status value it was still being added to the status map, but the server didn't check before dereferencing it. We now just check if the pointer is nil before trying to use it. Fixes: #2396 Signed-off-by: Patrick East --- server/server.go | 2 +- server/server_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index 094d3d8078..2649028af8 100644 --- a/server/server.go +++ b/server/server.go @@ -1008,7 +1008,7 @@ func (s *Server) unversionedGetHealth(w http.ResponseWriter, r *http.Request) { // Ensure that all plugins (if requested to be included in the result) have an OK status. hasErr := false for _, status := range pluginStatuses { - if status.State != plugins.StateOK { + if status != nil && status.State != plugins.StateOK { hasErr = true break } diff --git a/server/server_test.go b/server/server_test.go index e9e274f3b4..0522114393 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -326,7 +326,6 @@ func TestUnversionedGetHealthCheckDiscoveryWithPlugins(t *testing.T) { }, exp: 500, }, - { note: "all plugins ready - recovery", statusUpdates: map[string]*plugins.Status{ @@ -336,6 +335,13 @@ func TestUnversionedGetHealthCheckDiscoveryWithPlugins(t *testing.T) { }, exp: 200, }, + { + note: "nil plugin status", + statusUpdates: map[string]*plugins.Status{ + "p1": nil, + }, + exp: 200, + }, } for _, tc := range cases {