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

Fix config env vars that are prefix of another with underscore. #7748

Merged
merged 1 commit into from
Jan 6, 2020

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Dec 27, 2019

This fixes the CARGO_BUILD_TARGET_DIR and CARGO_PROFILE_DEV_DEBUG_ASSERTIONS environment variables. Hopefully the big comment explains everything, but to review:

deserialize_option does not know the type of the value it is about to deserialize. The type could be a struct, in which case it needs to check if CARGO_FOO_BAR_* environment variables are set. However, when deserializing something like build.target, this prefix check will incorrectly match CARGO_BUILD_TARGET_DIR which happens to be a prefix of CARGO_BUILD_TARGET_*. It attempts to call visit_some which fails if CARGO_BUILD_TARGET is not set.

The solution here is to detect scenarios where one field is a prefix of another, and skip the environment prefix check (by setting Deserializer::env_prefix_ok appropriately). This means we cannot have Option<SomeStruct> be a prefix of another field with an underscore. I think that's fine, and we should try to probably avoid these kinds a prefixes anyways.

Closes #7253.

@rust-highfive
Copy link

r? @alexcrichton

(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 Dec 27, 2019
@alexcrichton
Copy link
Member

@bors: r+

Nice catch!

@bors
Copy link
Collaborator

bors commented Jan 6, 2020

📌 Commit 829ddf0 has been approved by alexcrichton

@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 Jan 6, 2020
@bors
Copy link
Collaborator

bors commented Jan 6, 2020

⌛ Testing commit 829ddf0 with merge f7c5b1f...

bors added a commit that referenced this pull request Jan 6, 2020
Fix config env vars that are prefix of another with underscore.

This fixes the CARGO_BUILD_TARGET_DIR and CARGO_PROFILE_DEV_DEBUG_ASSERTIONS environment variables.  Hopefully the big comment explains everything, but to review:

`deserialize_option` does not know the type of the value it is about to deserialize.  The type could be a struct, in which case it needs to check if `CARGO_FOO_BAR_*` environment variables are set. However, when deserializing something like `build.target`, this prefix check will incorrectly match `CARGO_BUILD_TARGET_DIR` which happens to be a prefix of `CARGO_BUILD_TARGET_*`.  It attempts to call `visit_some` which fails if `CARGO_BUILD_TARGET` is not set.

The solution here is to detect scenarios where one field is a prefix of another, and skip the environment prefix check (by setting `Deserializer::env_prefix_ok` appropriately).  This means we cannot have `Option<SomeStruct>` be a prefix of another field with an underscore.  I think that's fine, and we should try to probably avoid these kinds a prefixes anyways.

Closes #7253.
@bors
Copy link
Collaborator

bors commented Jan 6, 2020

☀️ Test successful - checks-azure
Approved by: alexcrichton
Pushing f7c5b1f to master...

@bors bors merged commit 829ddf0 into rust-lang:master Jan 6, 2020
bors added a commit to rust-lang/rust that referenced this pull request Jan 7, 2020
Update cargo

9 commits in 86134e7666a088682f20b76278c3ee096a315218..6e1ca924a67dd1ac89c33f294ef26b5c43b89168
2019-12-23 16:08:07 +0000 to 2020-01-06 19:11:37 +0000
- Fix dynamic linking for Windows UWP MSVC targets (rust-lang/cargo#7758)
- Fix CARGO_TARGET_triple_LINKER environment variable. (rust-lang/cargo#7763)
- Remove metadata dep_kinds duplicates. (rust-lang/cargo#7756)
- Check for a source defined multiple times. (rust-lang/cargo#7751)
- Fix typo. (rust-lang/cargo#7735)
- Fix config env vars that are prefix of another with underscore. (rust-lang/cargo#7748)
- Add test for `cargo pkgid` (rust-lang/cargo#7741)
- Add a note to the error message for using --feature / --no-default-features in a virtual workspace (rust-lang/cargo#7742)
- Fix debug message. (rust-lang/cargo#7749)
@ehuss ehuss added this to the 1.42.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Can't set debug-assertions via -Z config-profile
4 participants