Skip to content

Beta backport: null terminate UNICODE_STRINGs #143275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions library/std/src/sys/fs/windows/remove_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ fn open_link_no_reparse(
static ATTRIBUTES: Atomic<u32> = AtomicU32::new(c::OBJ_DONT_REPARSE);

let result = unsafe {
static EMPTY_STR: [u16; 1] = [0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a comment explaining why this is necessary.

let mut path_str = c::UNICODE_STRING::from_ref(path);
if path_str.Length == 0 {
path_str.Buffer = EMPTY_STR.as_ptr().cast_mut();
}
let mut object = c::OBJECT_ATTRIBUTES {
ObjectName: &mut path_str,
RootDirectory: parent.as_raw_handle(),
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/pal/windows/pipe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
use crate::ops::Neg;
use crate::os::windows::prelude::*;
use crate::sys::api::utf16;
use crate::sys::api::wide_str;
use crate::sys::c;
use crate::sys::handle::Handle;
use crate::sys_common::{FromInner, IntoInner};
Expand Down Expand Up @@ -73,7 +73,8 @@ pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Res
// Open a handle to the pipe filesystem (`\??\PIPE\`).
// This will be used when creating a new annon pipe.
let pipe_fs = {
let path = c::UNICODE_STRING::from_ref(utf16!(r"\??\PIPE\"));
static PIPE_PATH: [u16; 10] = *wide_str!(r"\??\PIPE\");
let path = c::UNICODE_STRING::from_ref(&PIPE_PATH[..PIPE_PATH.len() - 1]);
object_attributes.ObjectName = &path;
let mut pipe_fs = ptr::null_mut();
let status = c::NtOpenFile(
Expand Down