GoogleContainerTools / GoogleContainerTools/container-structure-test

Crash when running in a container with an empty environment variable

Open
#280 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
2.5k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

When running in a container started with `-e EMPTY` and the `EMPTY` variable is either unset or the empty string, you get a crash like this:

```
panic: runtime error: index out of range

goroutine 7 [running]:
github.com/GoogleContainerTools/container-structure-test/pkg/drivers.convertSliceToMap(0xc420398270, 0xd, 0xd, 0x0)
/go/src/github.com/GoogleContainerTools/container-structure-test/pkg/drivers/driver.go:82 +0x169
github.com/GoogleContainerTools/container-structure-test/pkg/drivers.(*DockerDriver).GetConfig(0xc42008bba0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/go/src/github.com/GoogleContainerTools/container-structure-test/pkg/drivers/docker_driver.go:408 +0x3f5
github.com/GoogleContainerTools/container-structure-test/pkg/types/v2.FileExistenceTest.Run(0xc4202fc4a0, 0x13, 0xc4202fc500, 0x12, 0x1, 0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, ...)
/go/src/github.com/GoogleContainerTools/container-structure-test/pkg/types/v2/file_existence.go:91 +0x242
github.com/GoogleContainerTools/container-structure-test/pkg/types/v2.(*StructureTest).RunFileExistenceTests(0xc420001200, 0xc420216e40)
/go/src/github.com/GoogleContainerTools/container-structure-test/pkg/types/v2/structure.go:117 +0x43f
github.com/GoogleContainerTools/container-structure-test/pkg/types/v2.(*StructureTest).runAll(0xc420001200, 0xc420216e40, 0xc42005e1c0)
/go/src/github.com/GoogleContainerTools/container-structure-test/pkg/types/v2/structure.go:56 +0x69
created by github.com/GoogleContainerTools/container-structure-test/pkg/types/v2.(*StructureTest).RunAll
/go/src/github.com/GoogleContainerTools/container-structure-test/pkg/types/v2/structure.go:49 +0x75
```

That's because the `"Env"` part of the `"Config"` object received from the Docker daemon looks something like

```json
"Env": [
"EMPTY",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
]
```

and https://github.com/GoogleContainerTools/container-structure-test/blob/75451d12078c3e39944dfa2cc3ad6bc64e4b31c8/pkg/drivers/driver.go#L81-L82

isn't prepared for the missing `=`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.