Skip to content

Commit

Permalink
fixup: safety comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Oct 31, 2024
1 parent 680c880 commit abbf556
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wireguard-go-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,18 @@ impl Drop for Tunnel {
}
}

/// Check whether `machines` contains valid, LF-separated maybenot machines. Return an error
/// otherwise.
pub fn validate_maybenot_machines(machines: &CStr) -> Result<(), Error> {
use maybenot_ffi::MaybenotResult;

let mut framework = MaybeUninit::uninit();
// SAFETY: `machines` is a null-terminated string, and `&mut framework` is a valid pointer
let result =
unsafe { maybenot_ffi::maybenot_start(machines.as_ptr(), 0.0, 0.0, &mut framework) };

if result as u32 == MaybenotResult::Ok as u32 {
// SAFETY: `maybenot_start` succeeded, so `framework` points to a valid framework
unsafe { maybenot_ffi::maybenot_stop(framework.assume_init()) };
Ok(())
} else {
Expand Down

0 comments on commit abbf556

Please sign in to comment.