Crash when running in a container with an empty environment variable

Open Beginner friendly
#280 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
docker, go
Domain
devops

Research direction

Start in pkg/drivers/driver.go at lines 81-82 and trace convertSliceToMap through DockerDriver.GetConfig in pkg/drivers/docker_driver.go. Reproduce the case with a Docker environment entry lacking '=', then verify configuration parsing no longer panics and still handles normal KEY=VALUE entries.

Written by the indexing model from the issue text.

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

"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 =.

Dominant language
Go
Stars
2.5k
Forks
212
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GoogleContainerTools/container-structure-test

All issues in GoogleContainerTools/container-structure-test

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.