Skip to content

Commit 1c35596

Browse files
authored
Rollup merge of #101455 - thomcc:why-is-this-here, r=jyn514
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.
2 parents 7064344 + 850090d commit 1c35596

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ features = [
6767
"psapi",
6868
"impl-default",
6969
"timezoneapi",
70+
"winbase",
7071
]
7172

7273
[dev-dependencies]

src/bootstrap/util.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> {
197197
ptr::null_mut(),
198198
);
199199

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

0 commit comments

Comments
 (0)