Skip to content

Commit

Permalink
cli: check empty container and object attributes
Browse files Browse the repository at this point in the history
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 <andrey@nspcc.io>
  • Loading branch information
End-rey committed Oct 29, 2024
1 parent 5a9abed commit 43450f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/neofs-cli/modules/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/neofs-cli/modules/object/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down

0 comments on commit 43450f5

Please sign in to comment.