about summary refs log tree commit diff
path: root/library/std/src/env.rs
AgeCommit message (Collapse)AuthorLines
2024-05-29Elaborate about modifying env vars in multi-threaded programsTobias Bucher-18/+28
2024-05-29Add note about safety of `std::env::set_var` on WindowsTobias Bucher-5/+11
2024-05-29Make `std::env::{set_var, remove_var}` unsafe in edition 2024Tobias Bucher-20/+34
Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions. Fixes #27970. Fixes #90308. CC #124866.
2024-02-29Remove doc aliases to PATHTrevor Gross-2/+0
Remove aliases for `split_paths` and `join_paths` as should have been done in <https://github.com/rust-lang/rust/pull/119748> (Bors merged the wrong commit).
2024-02-29Rollup merge of #119748 - tgross35:suggest-path-split, r=AmanieuJacob Pratt-1/+17
Increase visibility of `join_path` and `split_paths` Add some crosslinking among `std::env` pages to make it easier to discover `join_paths` and `split_paths`. Also add aliases to help anyone searching for `PATH`.
2024-02-18Add uncontroversial syscall doc aliases to std docsSabrinaJewson-1/+2
2024-02-10Fix typoJosh Triplett-1/+1
Co-authored-by: Benjamin Peter <145429680+benjamin-nw@users.noreply.github.com>
2024-01-08Increase visibility of `join_path` and `split_paths`Trevor Gross-1/+17
Add some crosslinking among `std::env` pages. Also add aliases to help anyone searching for `PATH`.
2023-12-13Reformulate `std::env::{set,remove}_env` as safety noteTobias Bucher-24/+36
2023-10-18Add discussion that concurrent access to the environment is unsafeTobias Bucher-10/+28
The bug report #27970 has existed for 8 years, the actual bug dates back to Rust pre-1.0. I documented it since it's in the interest of the user to be aware of it. The note can be removed once #27970 is fixed.
2023-08-14add a csky-unknown-linux-gnuabiv2 targetDirreke-0/+1
2023-08-07Better Debug for Vars and VarsOsTamir Duberstein-4/+8
Display actual vars instead of two dots. The same was done for Args and ArgsOs in 275f9a04af6191e3aee3852a5a1713.
2023-04-11Rollup merge of #109894 - ↵Michael Goulet-12/+5
fleetingbytes:109893-var_os-never-returns-an-error, r=cuviper Remove Errors section from var_os docs Remove `Errors` section from `var_os` documentation, fixes #109893
2023-04-11Break up long first paragraphfleetingbytes-3/+4
Further referring to `var_os` as a "function" (like in `var`), rather than "method".
2023-04-04library/std: Add support for loongarch64zhaixiaojuan-0/+1
2023-04-03Preserve potential mood for equal or NUL signfleetingbytes-5/+3
Original `var_os` description said that it _may_ return an error if the value contains `=` or NUL. Let's make no promises on the `None` return value in these situation either, keep it in the [potential mood](https://en.wikipedia.org/wiki/Grammatical_mood#Potential).
2023-04-03Remove redundant empty linefleetingbytes-1/+0
one is enough
2023-04-03remove self-reference in var_os docfleetingbytes-1/+0
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2023-04-03add situation where var_os returns Nonefleetingbytes-1/+7
Re-introduced some of the former errors as situations where `None` is returned.
2023-04-03Update env.rsfleetingbytes-10/+0
Remove `Errors` section from `var_os` documentation
2022-12-11Rollup merge of #101648 - Timmmm:home_dir_docs, r=joshtriplettMatthias Krüger-1/+8
Better documentation for env::home_dir()'s broken behaviour This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684
2022-10-03Reword "has no meaning" per suggestionTim-2/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-09-28env::temp_dir: fix a typoRalf Jung-1/+1
2022-09-10Better documentation for env::home_dir()'s broken behaviourTim Hutt-1/+8
This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684
2022-05-24add aliases for current_dirjulio-0/+3
2022-05-09Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errorsbors-3/+3
Remove `#[rustc_deprecated]` This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`. I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-05-03Remove hard links from `env::current_exe` security exampleMartin Geisler-30/+17
The security example shows that `env::current_exe` will return the path used when the program was started. This is not really surprising considering how hard links work: after `ln foo bar`, the two files are _equivalent_. It is _not_ the case that `bar` is a “link” to `foo`, nor is `foo` a link to `bar`. They are simply two names for the same underlying data. The security vulnerability linked to seems to be different: there an attacker would start a SUID binary from a directory under the control of the attacker. The binary would respawn itself by executing the program found at `/proc/self/exe` (which the attacker can control). This is a real problem. In my opinion, the example given here doesn’t really show the same problem, it just shows a misunderstanding of what hard links are. I looked through the history a bit and found that the example was introduced in #33526. That PR actually has two commits, and the first (8478d48dad949b3b1374569a5391089a49094eeb) explains the race condition at the root of the linked security vulnerability. The second commit proceeds to replace the explanation with the example we have today. This commit reverts most of the second commit from #33526.
2022-04-14Remove use of `#[rustc_deprecated]`Jacob Pratt-3/+3
2022-03-27Link to std::io's platform-specific behavior disclaimerDavid Tolnay-2/+6
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-12/+12
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-11Add missing platform-specific information on current_dir and set_current_dirGuillaume Gomez-0/+10
2021-12-09Rollup merge of #89999 - talagrand:GetTempPath2, r=m-ou-seMatthias Krüger-12/+9
Update std::env::temp_dir to use GetTempPath2 on Windows when available. As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2. When the calling process is running as SYSTEM, a separate temporary directory will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes the behavior will be the same as before. This can help mitigate against attacks such as this one: https://medium.com/csis-techblog/cve-2020-1088-yet-another-arbitrary-delete-eop-a00b97d8c3e2 Compatibility risk: Software which relies on temporary files to communicate between SYSTEM and non-SYSTEM processes may be affected by this change. In many cases, such patterns may be vulnerable to the very attacks the new API was introduced to harden against. I'm unclear on the Rust project's tolerance for such change-of-behavior in the standard library. If anything, this PR is meant to raise awareness of the issue and hopefully start the conversation. How tested: Taking the example code from the documentation and running it through psexec (from SysInternals) on Win10 and Win11. On Win10: C:\test>psexec -s C:\test\main.exe <...> Temporary directory: C:\WINDOWS\TEMP\ On Win11: C:\test>psexec -s C:\test\main.exe <...> Temporary directory: C:\Windows\SystemTemp\
2021-10-30Add #[must_use] to remaining std functions (A-N)John Kugelman-0/+8
2021-10-18Update std::env::temp_dir to use GetTempPath2 on Windows when available.Eugene Talagrand-12/+9
As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2. When the calling process is running as SYSTEM, a separate temporary directory will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes the behavior will be the same as before.
2021-09-17library/std/env: Add 'm68k' to comment on ARCH constantJohn Paul Adrian Glaubitz-0/+1
2021-08-27Document `std::env::current_exe` rename behaviourChris Denton-0/+3
It might not be obvious that the "path of the current running executable" may (or may not) mean "at the time it was loaded".
2021-08-17Fix environment variable getter docsinquisitivecrystal-5/+14
2021-08-02Rollup merge of #86183 - inquisitivecrystal:env-nul, r=m-ou-seYuki Okushi-17/+9
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-07-29Fix may not to appropriate might not or must notAli Malik-4/+4
2021-07-23Fix parameter names in std::env documentation.Érico Nogueira Rolim-4/+3
The function parameters were renamed, but the documentation wasn't.
2021-07-05Improve env var getter docsAris Merchant-8/+5
2021-07-05Make `getenv` return an Option instead of a ResultAris Merchant-1/+1
2021-07-05Change env var getters to error recoverablyAris Merchant-15/+10
Before this, `std`'s env var getter functions would panic on receiving certain invalid inputs. This commit makes them return a `None` or `Err` instead.
2021-06-23Use HTTPS links where possibleSmitty-2/+2
2021-05-10change k to key and v to v in std::env modshirshak55-10/+10
2021-05-05Rollup merge of #84709 - joshtriplett:doc-alias-chdir, r=dtolnayRalf Jung-0/+1
Add doc alias for `chdir` to `std::env::set_current_dir` Searching for `chdir` in the Rust documentation produces no useful results. I wrote some code recently that called `libc::chdir` and manually handled errors, because I didn't realize that the safe `std::env::set_current_dir` existed. I searched for `chdir` and `change_dir` and `change_directory` (the latter two based on the precedent of unabbreviating set by `create_dir`), and I also read through `std::fs` expecting to potentially find it there. Given that none of those led to `std::env::set_current_dir`, I think that provides sufficient justification to add this specific alias.
2021-04-29Add doc alias for `chdir` to `std::env::set_current_dir`Josh Triplett-0/+1
Searching for `chdir` in the Rust documentation produces no useful results.
2021-04-29Link between std::env::{var, var_os} and std::env::{vars, vars_os}r00ster91-2/+11
2021-04-27Make sentence in env::args_os' docs plain and simpler00ster-1/+1
2021-04-25Change wordingr00ster-2/+2