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 <east.patrick@gmail.com>
This commit is contained in:
Patrick East
2020-05-12 16:07:57 -07:00
parent 8b5cbfa07c
commit 6c7d9daa94
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -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
}
+7 -1
View File
@@ -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 {