Skip to content

Commit f6d80af

Browse files
authored
Add fsetxattr safe rule (#285)
1 parent ccca72b commit f6d80af

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎rule-preprocessor/src/semantic.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn build_rustc_args(crate_root: &Path) -> Vec<String> {
5353
"rustls_ffi",
5454
"nix",
5555
"jiff",
56+
"xattr",
5657
] {
5758
if let Some(rlib) = find_rlib(deps.as_path(), dep) {
5859
args.push("--extern".to_string());

‎rules/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ brotli-sys = "0.3"
1515
rustls-ffi = { version = "0.15.3", default-features = false }
1616
nix = { version = "0.30", features = ["socket", "net", "fs", "poll", "time", "user", "dir", "term", "event", "hostname"] }
1717
jiff = "0.2"
18+
xattr = "1"

‎rules/src/modules.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,7 @@ pub mod unistd_tgt_unsafe;
162162
pub mod vector_tgt_refcount;
163163
#[path = r#"../vector/tgt_unsafe.rs"#]
164164
pub mod vector_tgt_unsafe;
165+
#[path = r#"../xattr/tgt_refcount.rs"#]
166+
pub mod xattr_tgt_refcount;
165167
#[path = r#"../xattr/tgt_unsafe.rs"#]
166168
pub mod xattr_tgt_unsafe;

‎rules/xattr/tgt_refcount.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
use libcc2rs::*;
5+
6+
#[cfg(target_os = "linux")]
7+
fn f1(a0: i32, a1: Ptr<u8>, a2: AnyPtr, a3: usize, a4: i32) -> i32 {
8+
match a4 {
9+
0 => {}
10+
__f => panic!("fsetxattr: unsupported flags {}", __f),
11+
}
12+
let __name = a1.to_rust_string();
13+
match FdRegistry::with_fd(a0, |__fd| nix::unistd::dup(__fd)) {
14+
Ok(__dup) => {
15+
let __file = ::std::fs::File::from(__dup);
16+
match a2
17+
.reinterpret_cast::<u8>()
18+
.with_slice(a3, |__v| xattr::FileExt::set_xattr(&__file, &__name, __v))
19+
{
20+
Ok(()) => 0,
21+
Err(__e) => {
22+
libcc2rs::cpp2rust_errno().write(__e.raw_os_error().unwrap_or(::libc::EIO));
23+
-1
24+
}
25+
}
26+
}
27+
Err(__e) => {
28+
libcc2rs::cpp2rust_errno().write(__e as i32);
29+
-1
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)