Skip to content

Commit 83e2f93

Browse files
committed
Fix IO Safety violation for test and sample code
Since rust 1.80 has been released, a runtime failure occurs, when FD ownership is vailated. Hence, remove the code which uses invalid FD. Ref. rust-lang/rust#124210 Signed-off-by: Manabu Sugimoto <[email protected]>
1 parent 518f0cd commit 83e2f93

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

libseccomp/src/error.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,12 @@ impl SeccompError {
184184
///
185185
/// ```
186186
/// # use libseccomp::*;
187-
/// # use std::os::fd::*;
188-
/// let mut ctx = ScmpFilterContext::new(ScmpAction::Allow)?;
189-
/// ctx.set_api_sysrawrc(true)?;
190-
/// match ctx.export_pfc(unsafe { OwnedFd::from_raw_fd(-2) }) {
187+
/// match set_api(1000) {
191188
/// Err(e) => {
192189
/// eprintln!("Error: {e}");
193190
/// if let Some(sys) = e.sysrawrc() {
194191
/// eprintln!("The system's raw error code: {sys}");
195-
/// assert_eq!(sys, -libc::EBADF);
192+
/// assert_eq!(sys, -libc::EINVAL);
196193
/// }
197194
/// }
198195
/// _ => println!("No error"),

libseccomp/tests/tests.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use libseccomp::*;
2-
use std::fs::File;
32
use std::io::{stdout, Error};
4-
use std::os::unix::io::FromRawFd;
53

64
#[cfg(feature = "const-syscall")]
75
mod known_syscall_names;
@@ -369,13 +367,9 @@ fn test_precompute() {
369367
fn test_export_functions() {
370368
let ctx = ScmpFilterContext::new(ScmpAction::Allow).unwrap();
371369

372-
let mut invalid_fd: File = unsafe { std::fs::File::from_raw_fd(-2) };
373-
374370
assert!(ctx.export_pfc(stdout()).is_ok());
375-
assert!(ctx.export_pfc(&mut invalid_fd).is_err());
376371

377372
assert!(ctx.export_bpf(stdout()).is_ok());
378-
assert!(ctx.export_bpf(&mut invalid_fd).is_err());
379373

380374
#[cfg(libseccomp_v2_6)]
381375
{

0 commit comments

Comments
 (0)