0.1.18 (older version) Thoroughness: Medium Understanding: Medium
by gitlab.com/phgsng on 2019-09-30
This review is from Crev, a distributed system for code reviews. To add your review, set up cargo-crev
.
The current version of Openat is 0.1.21.
0.1.18 (older version) Thoroughness: Medium Understanding: Medium
by gitlab.com/phgsng on 2019-09-30
Lib.rs has been able to verify that all files in the crate's tarball, except Cargo.lock
,
are in the crate's repository with a git tag matching the version. Please note that this check is still in beta, and absence of this confirmation does not mean that the files don't match.
Crates in the crates.io registry are tarball snapshots uploaded by crates' publishers. The registry is not using crates' git repositories, so there is a possibility that published crates have a misleading repository URL, or contain different code from the code in the repository.
To review the actual code of the crate, it's best to use cargo crev open openat
. Alternatively, you can download the tarball of openat v0.1.21 or view the source online.
Disclaimer: as far evaluating syscall usage is concerned, this review considers only the behavior on Linux.
Pros
FromRawFD
).Cons
dir.rs
Unsafe
Dir::_open()
callinglibc::open()
: return check ok; pointer arg obtained from safe Rust type.Dir::_sub_dir()
callinglibc::openat()
: return check ok; pointer arg obtained from safe Rust type.Dir::_read_link()
callinglibc::readlinkat()
: return check ok; pointer arg from safe, zeroedVec
; size passed properly; result then resized to return value..Dir::new_unnamed_file()
callingCStr::from_bytes_with_nul_unchecked()
: argument is static constant and null terminated.Dir::_open_file()
callinglibc::openat()
: return check ok; pointer arg from safe Rust type.Dir::_open_file()
callingFile::from_raw_fd()
: arg was obtained via ok syscall immediately above.Dir::_symlink()
callinglibc::symlinkat()
: return check ok; pointer args obtained from safe Rust types.Dir::_create_dir()
callinglibc::mkdirat()
: return check ok; pointer arg obtained from safe Rust type.Dir::_unlink()
callinglibc::unlinkat()
: return check ok; pointer args are sane.Dir::_stat()
callingmem::zeroed()
: used on stack allocated struct type.Dir::_stat()
callinglibc::fstatat()
: return check ok; pointer argpath
obtained from safe Rust type;struct stat
obtained from zeroed buffer._rename()
callinglibc::renameat()
: return check ok; pointer args from safe Rust types._hardlink()
callinglibc::linkat()
: return check ok; pointer args from safe Rust types._rename_flags()
callinglibc::syscall()
forrenameat(2)
: return check ok; pointer args from safe Rust types; (non-impl'd syscall wrapper, related to libc issue #1508).impl FromRawFd for Dir {}
: unsafe API.impl Drop for Dir {}
callinglibc::close()
: no checks for result, which is ok in dtor that must not fail. Checks forlibc::AT_FDCWD
which is used occasionally in arguments to internal APIs.Other gotchas
O_NOFOLLOW
in calls toopenat(2)
,fstatat(2)
.O_TMPFILE
inDir::new_unnamed_file()
: ok-ish and issues documented.last_os_error()
.libc::mode_t
tolibc::c_uint
for calls toopenat()
; apparently necessary on Freebsd; the rationale should be documented (see #21).Dir::symlink()
reverses order of argument of the syscall. This is unexpected but documented.list.rs
Unsafe
DirIter::next_entry()
: unsafe due to writes to errno and general MT unsafety of wrapped call toreaddir(3)
; ok due to errno residing in TLS. Result pointer is wrapped in option type, cannot point to an invalid object, not shared across threads (DirIter
is neither Send nor Sync), dropped properly, and not exposed publicly.impl Iterator for DirIter {}
: calls unsafenext_entry()
(see above); calls unsafe
CStr::from_ptr()on
const charpointer obtained earlier by call to
readdir(3)`` which guarantees null termination.impl Drop for DirIter {}
callinglibc::closedir()
: is only reached for valid objects.name.rs
AsPath
for converting various types to something useable with C APIs that take paths (CStr
, CString``). Lifetime bounds ensure this can be used efficiently and safely. No fishy casts.filetype.rs
metadata.rs
is.metadata.rs
struct stat
, so no issue here with lifetimes.