@@ -313,17 +313,26 @@ impl Error for VarError {
313
313
/// Sets the environment variable `key` to the value `value` for the currently running
314
314
/// process.
315
315
///
316
- /// Note that while concurrent access to environment variables is safe in Rust,
317
- /// some platforms only expose inherently unsafe non-threadsafe APIs for
318
- /// inspecting the environment. As a result, extra care needs to be taken when
319
- /// auditing calls to unsafe external FFI functions to ensure that any external
320
- /// environment accesses are properly synchronized with accesses in Rust.
316
+ /// Note that while concurrent access to environment variables ought to be safe
317
+ /// in Rust, some platforms only expose inherently unsafe non-threadsafe APIs
318
+ /// for inspecting the environment. As a result, using `set_var` or
319
+ /// `remove_var` in a multi-threaded Rust program can lead to undefined
320
+ /// behavior, for example in combination with DNS lookups from
321
+ /// [`std::net::ToSocketAddrs`]. This is a bug
322
+ /// ([rust#27970](https://github.com/rust-lang/rust/issues/27970)) and will be
323
+ /// fixed in a future version of Rust. Additionally, extra care needs to be
324
+ /// taken when auditing calls to unsafe external FFI functions to ensure that
325
+ /// any external environment accesses are properly synchronized with accesses
326
+ /// in Rust. Since Rust does not expose its environment lock directly, this
327
+ /// means that all accesses to the environment must go through Rust's [`var`].
321
328
///
322
329
/// Discussion of this unsafety on Unix may be found in:
323
330
///
324
331
/// - [Austin Group Bugzilla](https://austingroupbugs.net/view.php?id=188)
325
332
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
326
333
///
334
+ /// [`std::net::ToSocketAddrs`]: crate::net::ToSocketAddrs
335
+ ///
327
336
/// # Panics
328
337
///
329
338
/// This function may panic if `key` is empty, contains an ASCII equals sign `'='`
@@ -351,17 +360,26 @@ fn _set_var(key: &OsStr, value: &OsStr) {
351
360
352
361
/// Removes an environment variable from the environment of the currently running process.
353
362
///
354
- /// Note that while concurrent access to environment variables is safe in Rust,
355
- /// some platforms only expose inherently unsafe non-threadsafe APIs for
356
- /// inspecting the environment. As a result extra care needs to be taken when
357
- /// auditing calls to unsafe external FFI functions to ensure that any external
358
- /// environment accesses are properly synchronized with accesses in Rust.
363
+ /// Note that while concurrent access to environment variables ought to be safe
364
+ /// in Rust, some platforms only expose inherently unsafe non-threadsafe APIs
365
+ /// for inspecting the environment. As a result, using `set_var` or
366
+ /// `remove_var` in a multi-threaded Rust program can lead to undefined
367
+ /// behavior, for example in combination with DNS lookups from
368
+ /// [`std::net::ToSocketAddrs`]. This is a bug
369
+ /// ([rust#27970](https://github.com/rust-lang/rust/issues/27970)) and will be
370
+ /// fixed in a future version of Rust. Additionally, extra care needs to be
371
+ /// taken when auditing calls to unsafe external FFI functions to ensure that
372
+ /// any external environment accesses are properly synchronized with accesses
373
+ /// in Rust. Since Rust does not expose its environment lock directly, this
374
+ /// means that all accesses to the environment must go through Rust's [`var`].
359
375
///
360
376
/// Discussion of this unsafety on Unix may be found in:
361
377
///
362
378
/// - [Austin Group Bugzilla](https://austingroupbugs.net/view.php?id=188)
363
379
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
364
380
///
381
+ /// [`std::net::ToSocketAddrs`]: crate::net::ToSocketAddrs
382
+ ///
365
383
/// # Panics
366
384
///
367
385
/// This function may panic if `key` is empty, contains an ASCII equals sign
0 commit comments