Skip to content

Commit

Permalink
csi: fix panic in serializing nil allocs in volume API (#8735)
Browse files Browse the repository at this point in the history
- fix panic in serializing nil allocs in volume API
- prevent potential panic in serializing plugin allocs
  • Loading branch information
tgross committed Aug 25, 2020
1 parent d787c28 commit d6ad3be
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions command/agent/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6ad3be

Please sign in to comment.