Skip to content

Commit

Permalink
Rollup merge of #101455 - thomcc:why-is-this-here, r=jyn514
Browse files Browse the repository at this point in the history
Avoid UB in the Windows filesystem code in... bootstrap?

This basically a subset of the changes from #101171. I didn't think to look in src/bootstrap for more windows filesystem API usage, which was apparently a mistake on my part. It's kinda goofy that stuff like this is in here, but what are you gonna do, computers are awful.

I also added `winbase` to the `winapi` dep -- I tested this in a tmp crate but needed to add this to your Cargo.toml -- you `use winapi::stuff::winbase` in this function, but are relying on something else turning on that feature.
  • Loading branch information
Dylan-DPC authored Sep 8, 2022
2 parents 7064344 + 850090d commit 1c35596
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ features = [
"psapi",
"impl-default",
"timezoneapi",
"winbase",
]

[dev-dependencies]
Expand Down
10 changes: 6 additions & 4 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> {
ptr::null_mut(),
);

let mut data = [0u8; MAXIMUM_REPARSE_DATA_BUFFER_SIZE as usize];
let db = data.as_mut_ptr() as *mut REPARSE_MOUNTPOINT_DATA_BUFFER;
let buf = &mut (*db).ReparseTarget as *mut u16;
#[repr(C, align(8))]
struct Align8<T>(T);
let mut data = Align8([0u8; MAXIMUM_REPARSE_DATA_BUFFER_SIZE as usize]);
let db = data.0.as_mut_ptr() as *mut REPARSE_MOUNTPOINT_DATA_BUFFER;
let buf = core::ptr::addr_of_mut!((*db).ReparseTarget) as *mut u16;
let mut i = 0;
// FIXME: this conversion is very hacky
let v = br"\??\";
Expand All @@ -219,7 +221,7 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> {
let res = DeviceIoControl(
h as *mut _,
FSCTL_SET_REPARSE_POINT,
data.as_ptr() as *mut _,
db.cast(),
(*db).ReparseDataLength + 8,
ptr::null_mut(),
0,
Expand Down

0 comments on commit 1c35596

Please sign in to comment.