Skip to content

Commit 6913754

Browse files
committed
provider/docker: don't crash with empty commands
If any of the entries in `commands` on `docker_container` resources was empty, the assertion to string panic'd. Since we can't use ValidateFunc on list elements, we can only really check this at apply time. If any value is nil (resolves to empty string during conversion), we fail with an error prior to creating the container. Fixes hashicorp#6409.
1 parent 7a49c2d commit 6913754

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

builtin/providers/docker/resource_docker_container_funcs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
5151

5252
if v, ok := d.GetOk("command"); ok {
5353
createOpts.Config.Cmd = stringListToStringSlice(v.([]interface{}))
54+
for _, v := range createOpts.Config.Cmd {
55+
if v == "" {
56+
return fmt.Errorf("values for command may not be empty")
57+
}
58+
}
5459
}
5560

5661
if v, ok := d.GetOk("entrypoint"); ok {
@@ -269,6 +274,10 @@ func resourceDockerContainerDelete(d *schema.ResourceData, meta interface{}) err
269274
func stringListToStringSlice(stringList []interface{}) []string {
270275
ret := []string{}
271276
for _, v := range stringList {
277+
if v == nil {
278+
ret = append(ret, "")
279+
continue
280+
}
272281
ret = append(ret, v.(string))
273282
}
274283
return ret

0 commit comments

Comments
 (0)