Skip to content

Commit 42b2ad8

Browse files
authored
mknod: fix SELinux cleanup when context setting fails (#10582)
1 parent 562c5cc commit 42b2ad8

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/uu/mknod/src/mknod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
9494
config.context,
9595
) {
9696
// if it fails, delete the file
97-
let _ = std::fs::remove_dir(file_name);
97+
let _ = std::fs::remove_file(file_name);
9898
eprintln!("{}: {}", uucore::util_name(), e);
9999
return 1;
100100
}

tests/by-util/test_mknod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,21 @@ fn test_mknod_selinux_invalid() {
240240
}
241241
}
242242
}
243+
244+
#[test]
245+
#[cfg(feature = "feat_selinux")]
246+
fn test_mknod_selinux_invalid_cleanup() {
247+
let scene = TestScenario::new(util_name!());
248+
let at = &scene.fixtures;
249+
let dest = "test_fifo";
250+
251+
new_ucmd!()
252+
.arg("--context=invalid_context_t")
253+
.arg(at.plus_as_string(dest))
254+
.arg("p")
255+
.fails()
256+
.no_stdout();
257+
258+
// invalid context → node must not exist
259+
assert!(!at.file_exists(dest));
260+
}

0 commit comments

Comments
 (0)