From 18c1977f204dc000bedbbea44d73c03123933fa5 Mon Sep 17 00:00:00 2001 From: lyw458372 Date: Mon, 8 Jun 2026 19:18:59 +0800 Subject: [PATCH] fix: glob: handle non-UTF-8 paths without panicking --- src/header/glob/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/header/glob/mod.rs b/src/header/glob/mod.rs index 877cce9463..1bf7f4cc71 100644 --- a/src/header/glob/mod.rs +++ b/src/header/glob/mod.rs @@ -228,22 +228,18 @@ fn list_dir( true } else if (*entry).d_type == DT_LNK { // Resolve symbolic link - let mut full_path = path.to_owned_cstring().into_string().unwrap(); - if !full_path.ends_with('/') { - full_path.push('/'); + let mut full_path = path.to_bytes().to_vec(); + if !full_path.ends_with(b"/") { + full_path.push(b'/'); } - full_path.push_str(name.to_str().unwrap()); - full_path.push('\0'); + full_path.extend_from_slice(name.as_bytes()); + let full_path = CString::new(full_path).unwrap(); let mut link_info = stat::default(); - if stat( - full_path.as_ptr().cast::(), - ptr::from_mut(&mut link_info), - ) != 0 - { + if stat(full_path.as_ptr(), ptr::from_mut(&mut link_info)) != 0 { let errno = platform::ERRNO.get(); platform::ERRNO.set(old_errno); - if errfunc(full_path.as_ptr().cast::(), errno) != 0 || abort_on_error { + if errfunc(full_path.as_ptr(), errno) != 0 || abort_on_error { return Err(GLOB_ABORTED); } }