rust/library/std
Yuki Okushi 016612dc8d
Rollup merge of #86183 - inquisitivecrystal:env-nul, r=m-ou-se
Change environment variable getters to error recoverably

This PR changes the standard library environment variable getter functions to error recoverably (i.e. not panic) when given an invalid value.

On some platforms, it is invalid for environment variable names to contain `'\0'` or `'='`, or for their values to contain `'\0'`. Currently, the standard library panics when manipulating environment variables with names or values that violate these invariants. However, this behavior doesn't make a lot of sense, at least in the case of getters. If the environment variable is missing, the standard library just returns an error value, rather than panicking. It doesn't make sense to treat the case where the variable is invalid any differently from that. See the [internals thread](https://internals.rust-lang.org/t/why-should-std-var-panic/14847) for discussion. Thus, this PR changes the functions to error recoverably in this case as well.

If desired, I could change the functions that manipulate environment variables in other ways as well. I didn't do that here because it wasn't entirely clear what to change them to. Should they error silently or do something else? If someone tells me how to change them, I'm happy to implement the changes.

This fixes #86082, an ICE that arises from the current behavior. It also adds a regression test to make sure the ICE does not occur again in the future.

`@rustbot` label +T-libs
r? `@joshtriplett`
2021-08-02 11:03:15 +09:00
..
benches mv std libs to library/ 2020-07-27 19:51:13 -05:00
src Rollup merge of #86183 - inquisitivecrystal:env-nul, r=m-ou-se 2021-08-02 11:03:15 +09:00
tests Remove test for crypto feature ahead of its removal 2021-05-19 16:13:52 +01:00
build.rs Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
Cargo.toml macos current_exe using directly libc instead. 2021-07-25 06:02:07 +01:00