mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
mknod: fix SELinux cleanup when context setting fails (#10582)
This commit is contained in:
@@ -94,7 +94,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
|
||||
config.context,
|
||||
) {
|
||||
// if it fails, delete the file
|
||||
let _ = std::fs::remove_dir(file_name);
|
||||
let _ = std::fs::remove_file(file_name);
|
||||
eprintln!("{}: {}", uucore::util_name(), e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -240,3 +240,21 @@ fn test_mknod_selinux_invalid() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
fn test_mknod_selinux_invalid_cleanup() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let dest = "test_fifo";
|
||||
|
||||
new_ucmd!()
|
||||
.arg("--context=invalid_context_t")
|
||||
.arg(at.plus_as_string(dest))
|
||||
.arg("p")
|
||||
.fails()
|
||||
.no_stdout();
|
||||
|
||||
// invalid context → node must not exist
|
||||
assert!(!at.file_exists(dest));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user