Skip to content

Commit 8eb4554

Browse files
committed
Null terminate UNICODE_STRINGs
1 parent a8d097a commit 8eb4554

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

library/std/src/sys/fs/windows/remove_dir_all.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ fn open_link_no_reparse(
9090
static ATTRIBUTES: Atomic<u32> = AtomicU32::new(c::OBJ_DONT_REPARSE);
9191

9292
let result = unsafe {
93+
// Workaround for #143078.
94+
// While the Windows OS itself handles zero length strings,
95+
// some security software that hooks system functions may expect it to
96+
// be null terminated. So as a workaround we ensure zero length strings
97+
// always point to a zero u16 even though it should never be read.
98+
static EMPTY_STR: [u16; 1] = [0];
9399
let mut path_str = c::UNICODE_STRING::from_ref(path);
100+
if path_str.Length == 0 {
101+
path_str.Buffer = EMPTY_STR.as_ptr().cast_mut();
102+
}
94103
let mut object = c::OBJECT_ATTRIBUTES {
95104
ObjectName: &mut path_str,
96105
RootDirectory: parent.as_raw_handle(),

library/std/src/sys/pal/windows/pipe.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
22
use crate::ops::Neg;
33
use crate::os::windows::prelude::*;
4-
use crate::sys::api::utf16;
4+
use crate::sys::api::wide_str;
55
use crate::sys::c;
66
use crate::sys::handle::Handle;
77
use crate::sys_common::{FromInner, IntoInner};
@@ -73,7 +73,8 @@ pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Res
7373
// Open a handle to the pipe filesystem (`\??\PIPE\`).
7474
// This will be used when creating a new annon pipe.
7575
let pipe_fs = {
76-
let path = c::UNICODE_STRING::from_ref(utf16!(r"\??\PIPE\"));
76+
static PIPE_PATH: [u16; 10] = *wide_str!(r"\??\PIPE\");
77+
let path = c::UNICODE_STRING::from_ref(&PIPE_PATH[..PIPE_PATH.len() - 1]);
7778
object_attributes.ObjectName = &path;
7879
let mut pipe_fs = ptr::null_mut();
7980
let status = c::NtOpenFile(

0 commit comments

Comments
 (0)