Skip to content

Commit

Permalink
ParseRestartPolicy: validate for missing policy-names
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Aug 28, 2023
1 parent 4a763bf commit 167632b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cli/command/container/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ func TestParseRestartPolicy(t *testing.T) {
MaximumRetryCount: 0,
},
},
{
input: ":1",
expectedErr: "invalid restart policy format: no policy provided before colon",
},
{
input: "always",
expected: container.RestartPolicy{
Expand Down
5 changes: 4 additions & 1 deletion opts/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
return p, nil
}

k, v, _ := strings.Cut(policy, ":")
k, v, ok := strings.Cut(policy, ":")
if ok && k == "" {
return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: no policy provided before colon")
}
if v != "" {
count, err := strconv.Atoi(v)
if err != nil {
Expand Down

0 comments on commit 167632b

Please sign in to comment.