Skip to content

Commit a04e491

Browse files
committed
refactor(mkfifo): remove unsafe libc::mkfifo, use safe rustix::fs::mknodat
1 parent f4b60ba commit a04e491

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/mkfifo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ uucore = { workspace = true, features = ["fs", "mode"] }
2424
fluent = { workspace = true }
2525

2626
[target.'cfg(unix)'.dependencies]
27-
nix = { workspace = true, features = ["fs"] }
27+
libc = { workspace = true }
28+
rustix = { workspace = true, features = ["fs"] }
2829

2930
[features]
3031
selinux = ["uucore/selinux"]

src/uu/mkfifo/src/mkfifo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// file that was distributed with this source code.
55

66
use clap::{Arg, ArgAction, Command, value_parser};
7-
use nix::sys::stat::Mode;
8-
use nix::unistd::mkfifo;
97
use std::fs;
108
use std::os::unix::fs::PermissionsExt;
119
use uucore::display::Quotable;
@@ -48,7 +46,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
4846
};
4947

5048
for f in fifos {
51-
if mkfifo(f.as_str(), Mode::from_bits_truncate(0o666)).is_err() {
49+
let c_path = std::ffi::CString::new(f.as_str()).unwrap();
50+
// SAFETY: c_path is a valid null-terminated C string
51+
let ret = unsafe { libc::mkfifo(c_path.as_ptr(), 0o666) };
52+
if ret != 0 {
5253
show!(USimpleError::new(
5354
1,
5455
translate!("mkfifo-error-cannot-create-fifo", "path" => f.quote()),

0 commit comments

Comments
 (0)