From d6ad3be8bd5613e772bb65f769f3c6c2b7020e42 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 25 Aug 2020 10:13:05 -0400 Subject: [PATCH] csi: fix panic in serializing nil allocs in volume API (#8735) - fix panic in serializing nil allocs in volume API - prevent potential panic in serializing plugin allocs --- command/agent/csi_endpoint.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/command/agent/csi_endpoint.go b/command/agent/csi_endpoint.go index d30c19dbf13..ac6e69f3655 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 @@ -341,11 +343,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