From 5a0f1112ad539bc639dd12930914077752a2acf2 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Wed, 24 Jun 2026 09:06:05 -0700 Subject: [PATCH] std: reject interior NULs in UEFI env::join_paths segments UEFI join_paths only rejected ';' separators. Joined Path-style strings are later treated as C-style wide strings; embedded NULs would truncate segments. Reject them like the Windows join_paths fix. Signed-off-by: Sebastien Tardif --- library/std/src/sys/paths/uefi.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/paths/uefi.rs b/library/std/src/sys/paths/uefi.rs index 7fddcfdff7724..e49aec10294e4 100644 --- a/library/std/src/sys/paths/uefi.rs +++ b/library/std/src/sys/paths/uefi.rs @@ -89,7 +89,11 @@ where } let v = path.as_ref().encode_wide().collect::>(); - if v.contains(&PATHS_SEP) { + // Interior NULs would truncate when the joined string is later treated + // as a C-style wide string (e.g. the UEFI Shell Path variable). + if v.contains(&0) { + return Err(JoinPathsError); + } else if v.contains(&PATHS_SEP) { return Err(JoinPathsError); } @@ -101,7 +105,7 @@ where impl fmt::Display for JoinPathsError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - "path segment contains `;`".fmt(f) + "path segment contains `;` or interior NUL".fmt(f) } }