mknod: fix SELinux cleanup when context setting fails (#10582)

This commit is contained in:
ChiamakaUI
2026-01-31 15:12:59 -05:00
committed by GitHub
parent 562c5ccde5
commit 42b2ad83cd
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -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;
}
+18
View File
@@ -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));
}