diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-02-01 10:06:09 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-01 10:06:09 +0530 |
commit | 4f914dd1617bb2aa3a5a3f5a4b8dec9356e851c1 (patch) | |
tree | 0b90e662044abe1396ce1d3690d8e793d9cb8c3d /ext/fs/std_fs.rs | |
parent | e58b1900a7b018a36deff22fdd34f4676180a4bb (diff) |
fix(fs): copyFile NUL path on macOS (#22216)
Fixes https://github.com/denoland/deno/issues/22211
Diffstat (limited to 'ext/fs/std_fs.rs')
-rw-r--r-- | ext/fs/std_fs.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index bb8d114a0..c1c9200cb 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -413,10 +413,11 @@ fn copy_file(from: &Path, to: &Path) -> FsResult<()> { use std::io::Read; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::PermissionsExt; - use std::os::unix::prelude::OsStrExt; - let from_str = CString::new(from.as_os_str().as_bytes()).unwrap(); - let to_str = CString::new(to.as_os_str().as_bytes()).unwrap(); + let from_str = CString::new(from.as_os_str().as_encoded_bytes()) + .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?; + let to_str = CString::new(to.as_os_str().as_encoded_bytes()) + .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?; // SAFETY: `from` and `to` are valid C strings. // std::fs::copy does open() + fcopyfile() on macOS. We try to use @@ -555,8 +556,10 @@ fn cp(from: &Path, to: &Path) -> FsResult<()> { use std::ffi::CString; use std::os::unix::ffi::OsStrExt; - let from_str = CString::new(from.as_os_str().as_bytes()).unwrap(); - let to_str = CString::new(to.as_os_str().as_bytes()).unwrap(); + let from_str = CString::new(from.as_os_str().as_bytes()) + .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?; + let to_str = CString::new(to.as_os_str().as_bytes()) + .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?; // SAFETY: `from` and `to` are valid C strings. unsafe { |