Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around Windows bug where arguments are not properly quoted #3389

Merged
merged 9 commits into from
Jul 8, 2024

Conversation

Naatan
Copy link
Member

@Naatan Naatan commented Jul 4, 2024

TaskDX-2898 Executors mangle arguments if used on batch files

This works around a Go bug, which was filed here: golang/go#68313, and marked as duplicate of golang/go#15566, which was first reported nearly a decade ago (!!!). So rather than wait for a fix we're just going to work around it.

@Naatan Naatan changed the base branch from master to version/0-45-0-RC1 July 4, 2024 18:48
Comment on lines 8 to 17
func Command(name string, arg ...string) *exec.Cmd {
cmd := exec.Command(name, arg...)

// Go currently does not escape arguments properly on Windows, it account for spaces and tab characters, but not
// other characters that need escaping such as `<` and `>`.
// This can be dropped once we update to a Go version that fixes this bug: https://github.com/golang/go/issues/68313
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: makeCmdLine(cmd.Args)}

return cmd
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Note this is purposely duplicating logic in osutils, because a design principle behind executors is that we avoid reusing internal libraries so as to keep the executable as lightweight as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I've accidentally included things that blew up the exe size. Fortunately we have a test to catch it 😅

@Naatan Naatan requested a review from mitchell-as July 4, 2024 22:13
@Naatan Naatan changed the title Work around Windows bug where arguments are not properly escaped Work around Windows bug where arguments are not properly quoted Jul 4, 2024
Copy link
Contributor

@mitchell-as mitchell-as left a comment

Choose a reason for hiding this comment

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

Excellent work, and nice digging!

// For this test we don't care about the svc communication.
env := e2e.OptAppendEnv("ACTIVESTATE_CI=false")

inputs := []string{"a<b", "b>a", "hello world", "&whoami", "imnot|apipe", "%NotAppData%", "^NotEscaped", "(NotAGroup)"}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a nice set of test inputs!

@Naatan Naatan merged commit 71944be into version/0-45-0-RC1 Jul 8, 2024
12 of 13 checks passed
@Naatan Naatan deleted the DX-2898 branch July 8, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants