Skip to content

Commit

Permalink
fix(rust): catch panics in extern "C" functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thomcc committed Oct 30, 2021
1 parent 918b9de commit c623001
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 249 deletions.
3 changes: 3 additions & 0 deletions implementations/rust/ockam/ockam_ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub enum FfiError {

/// Ownership error.
OwnershipError,

/// Caught a panic (which would be UB if we let it unwind across the FFI).
UnexpectedPanic,
}

impl FfiError {
Expand Down
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_ffi/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
macro_rules! check_buffer {
($buffer:expr) => {
if $buffer.is_null() {
return FfiError::InvalidParam.into();
return Err(FfiError::InvalidParam.into());
}
};
($buffer:expr, $length:expr) => {
if $buffer.is_null() || $length == 0 {
return FfiError::InvalidParam.into();
return Err(FfiError::InvalidParam.into());
}
};
}
Loading

0 comments on commit c623001

Please sign in to comment.