From 48ab4aec31e6e9db162e6d9bfd32f61a6f367a38 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 8 Dec 2023 18:05:45 +0100 Subject: [PATCH] podman kube play: fix broken annotation parsing If a user did not set an equal sign in the annotation that old code would panic when accessing the second element in the slice. Signed-off-by: Paul Holzinger --- cmd/podman/kube/play.go | 2 +- test/system/700-play.bats | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/podman/kube/play.go b/cmd/podman/kube/play.go index 3de89ab31d..59643fc635 100644 --- a/cmd/podman/kube/play.go +++ b/cmd/podman/kube/play.go @@ -239,7 +239,7 @@ func play(cmd *cobra.Command, args []string) error { for _, annotation := range playOptions.annotations { splitN := strings.SplitN(annotation, "=", 2) - if len(splitN) > 2 { + if len(splitN) != 2 { return fmt.Errorf("annotation %q must include an '=' sign", annotation) } if playOptions.Annotations == nil { diff --git a/test/system/700-play.bats b/test/system/700-play.bats index d3bf0eddef..ee507cf176 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -444,6 +444,10 @@ _EOF is "$output" ".*name:$RANDOMSTRING" "Annotation should be added to pod" is "$output" ".*anno:$ANNOTATION_WITH_COMMA" "Annotation with comma should be added to pod" + # invalid annotation + run_podman 125 kube play --annotation "val" $PODMAN_TMPDIR/test.yaml + assert "$output" == "Error: annotation \"val\" must include an '=' sign" "invalid annotation error" + run_podman stop -a -t 0 run_podman pod rm -t 0 -f test_pod }