Skip to content

Conversation

@dcantah
Copy link
Contributor

@dcantah dcantah commented Sep 24, 2021

This change sets the PATHEXT environment variable which Go checks during
exec.Cmd startup to do some path resolution. PATHEXT contains a semicolon
separated list of extensions to check against if a path ended without one
(e.g. /path/to/my/binary). This simply adds an empty string entry to the end
so that binaries with no extension can be launched correctly. Although this isn't
a common occurrence it's still a good thing to support. Windows Server containers
are able to handle this fine, and CreateProcess is perfectly happy launching
a valid executable without an extension.

This is mainly to support the agnhost image which is a common k8s testing image whose
entrypoint is a binary named agnhost with no extension.
https://github.com/kubernetes/kubernetes/blob/d64e91878517b1208a0bce7e2b7944645ace8ede/test/images/agnhost/Dockerfile_windows

Signed-off-by: Daniel Canter [email protected]

This change sets the PATHEXT environment variable which Go checks during
exec.Cmd startup to do some path resolution. PATHEXT contains a semicolon
separated list of extensions to check against if a path ended without one
(e.g. /path/to/my/binary). This simply adds an empty string entry to the end
so that binaries with no extension can be launched correctly. Although this isn't
a common occurrence it's still a good thing to support. Windows Server containers
are able to handle this fine, and CreateProcess is perfectly happy launching
a valid executable without an extension.

This is mainly to support the agnhost image which is a common k8s testing image whose
entrypoint is a binary named agnhost with no extension.
https://github.com/kubernetes/kubernetes/blob/d64e91878517b1208a0bce7e2b7944645ace8ede/test/images/agnhost/Dockerfile_windows

Signed-off-by: Daniel Canter <[email protected]>
@dcantah dcantah requested a review from a team as a code owner September 24, 2021 00:47
Comment on lines +220 to +223
if err := os.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD; "); err != nil {
return nil, errors.Wrap(err, "failed to set PATHEXT")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add this only to the environment that's passed to the cmd instead of setting it on the running environment?

Copy link
Contributor Author

@dcantah dcantah Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to find the process to launch in the first place so nope. Basically exec.Cmd calls exec.LookPath as one of the steps before launching the process and this is what fails as it doesn't treat a file with an extension not in its default set of extensions (and no extension falls in this category) as valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're adding an empty string entry so it deems this as valid now.

@katiewasnothere katiewasnothere self-assigned this Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants