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

Windows: Fix Command::env_clear so it works if no variables are set #86467

Merged
merged 2 commits into from
Jun 24, 2021

Conversation

ChrisDenton
Copy link
Member

@ChrisDenton ChrisDenton commented Jun 19, 2021

Previously, it would error unless at least one new environment variable was added. The missing null presumably meant that Windows was reading random memory in that case.

See: CreateProcessW (scroll down to lpEnvironment). Essentially the environment block is a null terminated list of null terminated strings and an empty list is \0\0 and not \0.

EDIT: Oh, CreateEnvironmentBlock states this much more explicitly.

Fixes #31259

Previously, it would error unless at least one new environment variable was added.
@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2021
@JohnTitor
Copy link
Member

Looks reasonable to me, could you add a test to https://github.com/rust-lang/rust/blob/master/library/std/src/process/tests.rs?

@ChrisDenton
Copy link
Member Author

Ok, I've added a test and confirmed it fails without this patch and succeeds with it.

@JohnTitor
Copy link
Member

LGTM and confirmed that it worked well on my local, thanks!

r? @JohnTitor @bors r+

@bors
Copy link
Contributor

bors commented Jun 24, 2021

📌 Commit 16145a9 has been approved by JohnTitor

@rust-highfive rust-highfive assigned JohnTitor and unassigned m-ou-se Jun 24, 2021
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2021
@bors
Copy link
Contributor

bors commented Jun 24, 2021

⌛ Testing commit 16145a9 with merge cbeda5c...

@bors
Copy link
Contributor

bors commented Jun 24, 2021

☀️ Test successful - checks-actions
Approved by: JohnTitor
Pushing cbeda5c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 24, 2021
@bors bors merged commit cbeda5c into rust-lang:master Jun 24, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jun 24, 2021
@ChrisDenton ChrisDenton deleted the win-env-clear branch June 24, 2021 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

env_clear does not work on Windows
6 participants