container-structure-test icon indicating copy to clipboard operation
container-structure-test copied to clipboard

Crash when running in a container with an empty environment variable

Open jrosdahl opened this issue 4 years ago • 0 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 https://github.com/GoogleContainerTools/container-structure-test/blob/75451d12078c3e39944dfa2cc3ad6bc64e4b31c8/pkg/drivers/driver.go#L81-L82

isn't prepared for the missing =.

jrosdahl avatar Aug 17 '21 12:08 jrosdahl