Skip to content

Commit 730127d

Browse files
committed
Don't panic on NULL bytes
1 parent 776035e commit 730127d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "faccess"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
authors = ["Thomas Hurst <tom@hur.st>"]
55
edition = "2018"
66
description = "Simple file accessibility checks"

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ mod imp {
9090
const AT_EACCESS: c_int = 0;
9191

9292
fn eaccess(p: &Path, mode: c_int) -> io::Result<()> {
93-
let path = CString::new(p.as_os_str().as_bytes()).expect("Path can't contain NULL");
93+
let path = CString::new(p.as_os_str().as_bytes())?;
9494
unsafe {
9595
if faccessat(AT_FDCWD, path.as_ptr() as *const i8, mode, AT_EACCESS) == 0 {
9696
Ok(())
@@ -572,4 +572,6 @@ fn amazing_test_suite() {
572572
assert!(!missing.readable());
573573
assert!(!missing.writable());
574574
assert!(!missing.executable());
575+
576+
assert!(Path::new("\0").access(AccessMode::EXISTS).is_err());
575577
}

0 commit comments

Comments
 (0)