From 32f99238bb3a70b7a4f2992e2368ece6b8bbd41e Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 25 Aug 2020 09:08:01 -0400 Subject: [PATCH 1/2] csi: fix panic in serializing nil allocs in volume API --- command/agent/csi_endpoint.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/command/agent/csi_endpoint.go b/command/agent/csi_endpoint.go index d30c19dbf136..b381cd46105b 100644 --- a/command/agent/csi_endpoint.go +++ b/command/agent/csi_endpoint.go @@ -341,11 +341,15 @@ func structsCSIVolumeToApi(vol *structs.CSIVolume) *api.CSIVolume { } for _, a := range vol.WriteAllocs { - out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub())) + if a != nil { + out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub())) + } } for _, a := range vol.ReadAllocs { - out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub())) + if a != nil { + out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub())) + } } return out From 8b8738b573400d985fe60d4a62edee2aff4835cc Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 25 Aug 2020 09:10:10 -0400 Subject: [PATCH 2/2] csi: prevent potential panic in serializing plugin allocs --- command/agent/csi_endpoint.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/command/agent/csi_endpoint.go b/command/agent/csi_endpoint.go index b381cd46105b..ac6e69f36554 100644 --- a/command/agent/csi_endpoint.go +++ b/command/agent/csi_endpoint.go @@ -296,7 +296,9 @@ func structsCSIPluginToApi(plug *structs.CSIPlugin) *api.CSIPlugin { } for _, a := range plug.Allocations { - out.Allocations = append(out.Allocations, structsAllocListStubToApi(a)) + if a != nil { + out.Allocations = append(out.Allocations, structsAllocListStubToApi(a)) + } } return out