GoogleContainerTools / container-structure-test

validate the structure of your container images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when running in a container with an empty environment variable

jrosdahl opened this issue · comments

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

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

and

pair := strings.SplitN(slicePair, "=", 2)
res[pair[0]] = pair[1]

isn't prepared for the missing =.