File tree Expand file tree Collapse file tree
crates/fspy_shared_unix/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ use std::{
77use bstr:: BStr ;
88use elf:: { ElfBytes , abi:: PT_INTERP , endian:: AnyEndian } ;
99
10+ /// Checks whether the given ELF executable is dynamically linked to libc.
11+ ///
12+ /// # Errors
13+ ///
14+ /// Returns `ENOEXEC` if the binary cannot be parsed as a valid ELF file.
1015pub fn is_dynamically_linked_to_libc ( executable : impl AsRef < [ u8 ] > ) -> nix:: Result < bool > {
1116 let executable = executable. as_ref ( ) ;
1217 let Some ( interp) = get_interp ( executable) ? else {
@@ -20,8 +25,8 @@ pub fn is_dynamically_linked_to_libc(executable: impl AsRef<[u8]>) -> nix::Resul
2025}
2126
2227fn get_interp ( executable : & [ u8 ] ) -> nix:: Result < Option < & BStr > > {
23- let elf = ElfBytes :: < ' _ , AnyEndian > :: minimal_parse ( executable . as_ref ( ) )
24- . map_err ( |_| nix:: Error :: ENOEXEC ) ?;
28+ let elf =
29+ ElfBytes :: < ' _ , AnyEndian > :: minimal_parse ( executable ) . map_err ( |_| nix:: Error :: ENOEXEC ) ?;
2530 let Some ( headers) = elf. segments ( ) else {
2631 return Ok ( None ) ;
2732 } ;
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ pub struct ParseShebangOptions {
1717 pub split_arguments : bool , // TODO: recursive
1818}
1919
20+ #[ expect(
21+ clippy:: derivable_impls,
22+ reason = "on macOS split_arguments defaults to true via cfg!, which is not derivable"
23+ ) ]
2024impl Default for ParseShebangOptions {
2125 fn default ( ) -> Self {
2226 Self { split_arguments : cfg ! ( target_vendor = "apple" ) }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ pub struct Payload {
1515 pub artifacts : Artifacts ,
1616
1717 #[ cfg( target_os = "linux" ) ]
18+ #[ expect( clippy:: struct_field_names, reason = "descriptive field name for clarity" ) ]
1819 pub seccomp_payload : fspy_seccomp_unotify:: payload:: SeccompPayload ,
1920}
2021
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ const LD_PRELOAD: &str = "LD_PRELOAD";
1414
1515pub struct PreExec ( SeccompPayload ) ;
1616impl PreExec {
17+ /// Installs the seccomp unotify filter for the current process.
18+ ///
19+ /// # Errors
20+ ///
21+ /// Returns an error if the seccomp filter installation fails.
1722 pub fn run ( & self ) -> nix:: Result < ( ) > {
1823 install_target ( & self . 0 )
1924 }
@@ -24,6 +29,7 @@ pub fn handle_exec(
2429 encoded_payload : & EncodedPayload ,
2530) -> nix:: Result < Option < PreExec > > {
2631 let executable_fd = open_executable ( Path :: new ( OsStr :: from_bytes ( & command. program ) ) ) ?;
32+ // SAFETY: The file descriptor is valid and we only read from the mapping.
2733 let executable_mmap = unsafe { Mmap :: map ( & executable_fd) }
2834 . map_err ( |io_error| nix:: Error :: try_from ( io_error) . unwrap_or ( nix:: Error :: UnknownErrno ) ) ?;
2935 if elf:: is_dynamically_linked_to_libc ( executable_mmap) ? {
You can’t perform that action at this time.
0 commit comments