From 43450f56df44e67e32d387c909a07c1d623149ce Mon Sep 17 00:00:00 2001 From: Andrey Butusov Date: Tue, 29 Oct 2024 13:11:10 +0300 Subject: [PATCH] cli: check empty container and object attributes Check for the key and value of the container attributes for emptiness to prevent panic in the sdk. Check for the key and value of the object attributes for emptiness to prevent error from rpc. Signed-off-by: Andrey Butusov --- cmd/neofs-cli/modules/container/create.go | 6 ++++++ cmd/neofs-cli/modules/object/put.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/cmd/neofs-cli/modules/container/create.go b/cmd/neofs-cli/modules/container/create.go index 5496d13bcf..6b50c0704b 100644 --- a/cmd/neofs-cli/modules/container/create.go +++ b/cmd/neofs-cli/modules/container/create.go @@ -238,6 +238,12 @@ func parseAttributes(dst *container.Container, attributes []string) error { "you need to use one of them or make it equal") } + if kvPair[0] == "" { + return errors.New("empty attribute key") + } else if kvPair[1] == "" { + return fmt.Errorf("empty attribute value for key %s", kvPair[0]) + } + dst.SetAttribute(kvPair[0], kvPair[1]) } diff --git a/cmd/neofs-cli/modules/object/put.go b/cmd/neofs-cli/modules/object/put.go index 264cc2260c..d69c4f277d 100644 --- a/cmd/neofs-cli/modules/object/put.go +++ b/cmd/neofs-cli/modules/object/put.go @@ -225,6 +225,12 @@ func parseObjectAttrs(cmd *cobra.Command, ctx context.Context) ([]object.Attribu } } + if kv[0] == "" { + return nil, errors.New("empty attribute key") + } else if kv[1] == "" { + return nil, fmt.Errorf("empty attribute value for key %s", kv[0]) + } + attrs[i].SetKey(kv[0]) attrs[i].SetValue(kv[1]) }