Skip to content

os/exec: Command does not pass absolute path to argv[0] #17536

@APTy

Description

@APTy

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

darwin amd64

What did you do?

Run sshd in exec.Command() fails due to an incorrect absolute path.
https://play.golang.org/p/z1UMtdSY2N

What did you expect to see?

Successful execution of the command

Server listening on 0.0.0.0 port 8022.
Server listening on :: port 8022.

What did you see instead?

A message indicating that the command was not executed as it should be.

sshd re-exec requires execution with an absolute path

Discussion

exec.Command does in fact expand the absolute path of a command and save it to cmd.Path; however, it does not update the value of cmd.Args[0], which remains the original string name.

Even though the executed program is run correctly from its full system path, programs like sshd may make application-level checks against argv[0]. In these cases, we see the failure case as above.

Note that this may be intentional, but the docs for Command state that the path is resolved to a complete name, which makes the behavior above a little unexpected.

If name contains no path separators, Command uses LookPath to resolve the path to a complete name if possible. Otherwise it uses name directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions