Skip to content

Commit 4ac7bcb

Browse files
committed
Auto merge of rust-lang#129962 - pietroalbini:pa-cve-2024-43402-nightly, r=Amanieu
[nightly] Fix CVE-2024-43402 Include the for CVE-2024-43402 in nightly. See [GHSA-2xg3-7mm6-98jj](GHSA-2xg3-7mm6-98jj) for more information about it. r? `@ghost`
2 parents 842d6fc + c811d31 commit 4ac7bcb

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::time::Duration;
1313
#[macro_use]
1414
pub mod compat;
1515

16-
mod api;
16+
pub mod api;
1717

1818
pub mod args;
1919
pub mod c;

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,24 @@ impl Command {
272272
None
273273
};
274274
let program = resolve_exe(&self.program, || env::var_os("PATH"), child_paths)?;
275-
// Case insensitive "ends_with" of UTF-16 encoded ".bat" or ".cmd"
276-
let is_batch_file = matches!(
277-
program.len().checked_sub(5).and_then(|i| program.get(i..)),
278-
Some([46, 98 | 66, 97 | 65, 116 | 84, 0] | [46, 99 | 67, 109 | 77, 100 | 68, 0])
279-
);
275+
let has_bat_extension = |program: &[u16]| {
276+
matches!(
277+
// Case insensitive "ends_with" of UTF-16 encoded ".bat" or ".cmd"
278+
program.len().checked_sub(4).and_then(|i| program.get(i..)),
279+
Some([46, 98 | 66, 97 | 65, 116 | 84] | [46, 99 | 67, 109 | 77, 100 | 68])
280+
)
281+
};
282+
let is_batch_file = if path::is_verbatim(&program) {
283+
has_bat_extension(&program[..program.len() - 1])
284+
} else {
285+
super::fill_utf16_buf(
286+
|buffer, size| unsafe {
287+
// resolve the path so we can test the final file name.
288+
c::GetFullPathNameW(program.as_ptr(), size, buffer, ptr::null_mut())
289+
},
290+
|program| has_bat_extension(program),
291+
)?
292+
};
280293
let (program, mut cmd_str) = if is_batch_file {
281294
(
282295
command_prompt()?,

library/std/src/sys/path/windows.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::ffi::{OsStr, OsString};
22
use crate::path::{Path, PathBuf, Prefix};
3+
use crate::sys::api::utf16;
34
use crate::sys::pal::{c, fill_utf16_buf, os2path, to_u16s};
45
use crate::{io, ptr};
56

@@ -19,6 +20,10 @@ pub fn is_verbatim_sep(b: u8) -> bool {
1920
b == b'\\'
2021
}
2122

23+
pub fn is_verbatim(path: &[u16]) -> bool {
24+
path.starts_with(utf16!(r"\\?\")) || path.starts_with(utf16!(r"\??\"))
25+
}
26+
2227
/// Returns true if `path` looks like a lone filename.
2328
pub(crate) fn is_file_name(path: &OsStr) -> bool {
2429
!path.as_encoded_bytes().iter().copied().any(is_sep_byte)

tests/ui/std/windows-bat-args.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ fn parent() {
3232
let bat2 = String::from(bat.to_str().unwrap());
3333
bat.set_file_name("windows-bat-args3.bat");
3434
let bat3 = String::from(bat.to_str().unwrap());
35-
let bat = [bat1.as_str(), bat2.as_str(), bat3.as_str()];
35+
bat.set_file_name("windows-bat-args1.bat .. ");
36+
let bat4 = String::from(bat.to_str().unwrap());
37+
let bat = [bat1.as_str(), bat2.as_str(), bat3.as_str(), bat4.as_str()];
3638

3739
check_args(&bat, &["a", "b"]).unwrap();
3840
check_args(&bat, &["c is for cat", "d is for dog"]).unwrap();

0 commit comments

Comments
 (0)