-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 UB in std::sys::os::getenv()
#114968
Fix UB in std::sys::os::getenv()
#114968
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Same changes seems also needed for https://github.com/rust-lang/rust/blob/master/library/std/src/sys/solid/os.rs#L173 there are same patterns |
ce33746
to
83c713b
Compare
std::sys::unix::os::getenv()
std::sys::os::getenv()
Thanks for pointing out, I also copied EDIT: Same problem with |
Wasn't the Err case of the guard something that held a nested guard? |
@@ -81,6 +81,10 @@ pub fn current_exe() -> io::Result<PathBuf> { | |||
|
|||
static ENV_LOCK: RwLock<()> = RwLock::new(()); | |||
|
|||
pub fn env_read_lock() -> impl Drop { | |||
ENV_LOCK.read().unwrap_or_else(PoisonError::into_inner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but isn't actually needed.
@bors r+ |
pub type LockResult<Guard> = Result<Guard, PoisonError<Guard>>;
pub struct PoisonError<T> {
guard: T,
} You're right, the lock is acquired regardless of the variant, so the result can be used as-is. |
Topic mentioned some loop iterations, but test didn't added here? |
I couldn't find any text or code (to copy from) to make a Miri test, but if you have one, I can add a test. |
⌛ Testing commit 83c713b with merge d740f54773594676ef4bb6d1cdac26c968323494... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
@rustbot author |
Hm, this PR shouldn't be affecting windows targets, not even mingw? Also weird that it's a rustdoc failure. My guess would be it's spurious. |
@bors retry |
@bors ping |
😪 I'm awake I'm awake |
@bors r+ |
💡 This pull request was already approved, no need to approve it again.
|
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#114834 (Avoid side-effects from `try_coerce` when suggesting borrowing LHS of cast) - rust-lang#114968 (Fix UB in `std::sys::os::getenv()`) - rust-lang#114976 (Ignore unexpected incr-comp session dirs) - rust-lang#114999 (Migrate GUI colors test to original CSS color format) - rust-lang#115000 (custom_mir: change Call() terminator syntax to something more readable) r? `@ghost` `@rustbot` modify labels: rollup
Add data race test to `std::env::{get, set}` Complements rust-lang#114968, closes rust-lang#114949.
…ison-error-in-os, r=cuviper kmc-solid: Import `std::sync::PoisonError` in `std::sys::solid::os` Follow-up to rust-lang#114968. Fixes a missing import in [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. ``` error[E0433]: failed to resolve: use of undeclared type `PoisonError` C:\Users\xxxxx\.rustup\toolchains\nightly-2023-08-23-x86_64-pc-windows-gnu\lib\rustlib\src\rust\library\std\src\sys\solid\os.rs(85,36) | 85 | ENV_LOCK.read().unwrap_or_else(PoisonError::into_inner) | ^^^^^^^^^^^ use of undeclared type `PoisonError` | ```
Fixes #114949.
Reduced the loops to 1k iterations (100k was taking way too long), Miri no longer shows any UB.
@rustbot label +A-process +C-bug +I-unsound +O-unix