From 4083ddbb003d486ee63314d2bcbe851ec5148987 Mon Sep 17 00:00:00 2001 From: Ygal Blum Date: Sun, 24 Dec 2023 10:30:27 +0200 Subject: [PATCH] Kube Generate - check options in bind-mount-options exist before accessing Verify that the separator ':' was found before splitting the string [NO NEW TESTS NEEDED] Signed-off-by: Ygal Blum --- pkg/specgen/generate/kube/kube.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index f3e0b4920e..b7266ef978 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -488,7 +488,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener // Make sure the z/Z option is not already there (from editing the YAML) if k == define.BindMountPrefix { lastIndex := strings.LastIndex(v, ":") - if v[:lastIndex] == volumeSource.Source && !cutil.StringInSlice("z", options) && !cutil.StringInSlice("Z", options) { + if lastIndex != -1 && v[:lastIndex] == volumeSource.Source && !cutil.StringInSlice("z", options) && !cutil.StringInSlice("Z", options) { options = append(options, v[lastIndex+1:]) } }