rust/library/std/src
Matthias Krüger 0ed046f44d
Rollup merge of #101171 - thomcc:fix-winfs-ub, r=ChrisDenton
Fix UB from misalignment and provenance widening in `std::sys::windows`

This fixes two types of UB:

1. Reading past the end of a reference in types like `&c::REPARSE_DATA_BUFFER` (see https://github.com/rust-lang/unsafe-code-guidelines/issues/256). This is fixed by using `addr_of!`. I think there are probably a couple more cases where we do this for other structures, and will look into it in a bit.

2. Failing to ensure that a `[u8; N]` on the stack is sufficiently aligned to convert to a `REPARSE_DATA_BUFFER`. ~~This was done by introducing a new `AlignedAs` struct that allows aligning one type to the alignment of another type. I expect there are other places where we have this issue too, or I wouldn't introduce this type, but will get to them after this lands.~~

    ~~Worth noting, it *is* implemented in a way that can cause problems depending on how we fix #81996, but this would be caught by the test I added (and presumably if we decide to fix that in a way that would break this code, we'd also introduce a `#[repr(simple)]` or `#[repr(linear)]` as a replacement for this usage of `#[repr(C)]`).~~

    Edit: None of that is still in the code, I just went with a `Align8` since that's all we'll need for almost everything we want to call.

These are more or less "potential UB" since it's likely at the moment everything works fine, although the alignment not causing issues might just be down to luck (and x86 being forgiving).

~~NB: I've only ensured this check builds, but will run tests soon.~~ All tests pass, including stage2 compiler tests.

r? ``@ChrisDenton``
2022-08-31 07:58:01 +02:00
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Move error trait into core 2022-08-22 13:28:25 -07:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error remove fn backtrace 2022-08-01 20:10:40 +00:00
f32 Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
f64 Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
ffi Guarantee try_reserve preserves the contents on error 2022-08-10 01:51:38 +09:00
fs Ignore hiberfil_sys test in CI 2022-07-18 15:06:07 +01:00
io Rollup merge of #100819 - WaffleLapkin:use_ptr_byte_methods, r=scottmcm 2022-08-29 16:49:43 +05:30
net Rollup merge of #94890 - marmeladema:ip-addr-try-from-bytes, r=joshtriplett 2022-08-29 06:34:41 +02:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Rollup merge of #96334 - devnexen:socket_mark, r=dtolnay 2022-08-29 06:34:42 +02:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path make many std tests work in Miri 2022-08-18 18:07:39 -04:00
personality Move personality functions to std 2022-08-23 16:12:58 +08:00
prelude Finish bumping stage0 2022-05-27 07:36:17 -04:00
process Add test for issue #95178 2022-03-23 05:33:44 +00:00
sync make many std tests work in Miri 2022-08-18 18:07:39 -04:00
sys Rollup merge of #101171 - thomcc:fix-winfs-ub, r=ChrisDenton 2022-08-31 07:58:01 +02:00
sys_common Auto merge of #100201 - RalfJung:thread-local-key, r=thomcc 2022-08-28 15:12:31 +00:00
thread update and extend some comments, and cfg-out some unused code 2022-08-22 09:14:33 -04:00
time make many std tests work in Miri 2022-08-18 18:07:39 -04:00
alloc.rs Update std::alloc::System docs 2022-06-26 16:31:29 +02:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs Adjust backtrace stabilization version to CURRENT_RUSTC_VERSION 2022-08-27 17:08:53 +02:00
env.rs add aliases for current_dir 2022-05-24 19:41:40 -07:00
error.rs error::Error: remove some comments 2022-08-25 07:42:07 +01:00
f32.rs Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
f64.rs Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
fs.rs Rollup merge of #98801 - joshtriplett:file-create-new, r=thomcc 2022-08-29 16:49:38 +05:30
keyword_docs.rs Rollup merge of #98169 - pierwill:dyn-disp, r=JohnTitor 2022-06-17 07:16:58 +09:00
lazy.rs Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
lib.rs Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrum 2022-08-30 05:48:22 +00:00
macros.rs Rollup merge of #99742 - sigaloid:master, r=thomcc 2022-08-26 14:08:44 +02:00
num.rs Add Saturating type (based on Wrapping type) 2021-08-10 19:27:01 +02:00
panic.rs Support unstable moves via stable in unstable items 2022-07-08 21:18:13 +00:00
panicking.rs Auto merge of #92461 - rust-lang:const_tls_local_panic_count, r=Mark-Simulacrum 2022-05-23 13:04:59 +00:00
path.rs Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnay 2022-06-20 07:37:41 +09:00
personality.rs Move personality functions to std 2022-08-23 16:12:58 +08:00
primitive_docs.rs Add the syntax of references to their documentation summary. 2022-08-26 10:47:03 -07:00
process.rs Make doc for stdin field of process consistent 2022-08-21 01:56:26 -07:00
rt.rs Change Termination::report return type to ExitCode 2022-01-28 12:53:36 -08:00
time.rs Support setting file accessed/modified timestamps 2022-07-15 02:54:06 -07:00