Skip to content

Commit

Permalink
Don't panic on NULL bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaky committed Apr 1, 2020
1 parent 776035e commit 730127d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faccess"
version = "0.2.2"
version = "0.2.3"
authors = ["Thomas Hurst <tom@hur.st>"]
edition = "2018"
description = "Simple file accessibility checks"
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod imp {
const AT_EACCESS: c_int = 0;

fn eaccess(p: &Path, mode: c_int) -> io::Result<()> {
let path = CString::new(p.as_os_str().as_bytes()).expect("Path can't contain NULL");
let path = CString::new(p.as_os_str().as_bytes())?;
unsafe {
if faccessat(AT_FDCWD, path.as_ptr() as *const i8, mode, AT_EACCESS) == 0 {
Ok(())
Expand Down Expand Up @@ -572,4 +572,6 @@ fn amazing_test_suite() {
assert!(!missing.readable());
assert!(!missing.writable());
assert!(!missing.executable());

assert!(Path::new("\0").access(AccessMode::EXISTS).is_err());
}

0 comments on commit 730127d

Please sign in to comment.