From 45c91ab0f1f1c5d3892c39b838be2db56a8e63a1 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 20 Mar 2025 10:31:39 +0100 Subject: [PATCH] rbd: prevent panic in CreateVolumeGroup if volumeID was not found When an incorrect volumeID is passed while creating a VolumeGroup, the `.Destroy()` function caused a panic. By appending each volume to the volumes slice, the slice won't contain any `nil` volumes anymore. Signed-off-by: Niels de Vos --- internal/csi-addons/rbd/volumegroup.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/csi-addons/rbd/volumegroup.go b/internal/csi-addons/rbd/volumegroup.go index 01ea6a39c..9eb46daa9 100644 --- a/internal/csi-addons/rbd/volumegroup.go +++ b/internal/csi-addons/rbd/volumegroup.go @@ -89,7 +89,7 @@ func (vs *VolumeGroupServer) CreateVolumeGroup( defer mgr.Destroy(ctx) // resolve all volumes - volumes := make([]types.Volume, len(req.GetVolumeIds())) + volumes := make([]types.Volume, 0) defer func() { for _, vol := range volumes { vol.Destroy(ctx) @@ -105,7 +105,7 @@ func (vs *VolumeGroupServer) CreateVolumeGroup( req.GetName(), err.Error()) } - volumes[i] = vol + volumes = append(volumes, vol) } log.DebugLog(ctx, "all %d Volumes for VolumeGroup %q have been found", len(volumes), req.GetName())