-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent use-after-free in FFI method return
Signed-off-by: Marin Veršić <[email protected]>
- Loading branch information
Showing
12 changed files
with
232 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::mem::MaybeUninit; | ||
|
||
use iroha_ffi::{ffi_export, slice::OutBoxedSlice, FfiType}; | ||
|
||
type Nested = Vec<Vec<FfiStruct>>; | ||
|
||
/// Ffi structure | ||
#[derive(Clone, FfiType)] | ||
pub struct FfiStruct; | ||
|
||
/// Return nested structure | ||
#[ffi_export] | ||
pub fn return_nested() -> Nested { | ||
vec![vec![FfiStruct, FfiStruct], vec![FfiStruct, FfiStruct]] | ||
} | ||
|
||
fn main() { | ||
let mut params_len = MaybeUninit::uninit(); | ||
let nested = OutBoxedSlice::from_uninit_slice(None, &mut params_len); | ||
unsafe { __return_nested(nested) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0277]: the trait bound `IrVec<FfiStruct, Opaque<FfiStruct>>: NonLocal` is not satisfied | ||
--> tests/ui_fail/nested_owned_structure.rs:12:1 | ||
| | ||
12 | #[ffi_export] | ||
| ^^^^^^^^^^^^^ the trait `NonLocal` is not implemented for `IrVec<FfiStruct, Opaque<FfiStruct>>` | ||
| | ||
= help: the following other types implement trait `NonLocal`: | ||
&'__iroha_ffi_itm FfiStruct | ||
&'__iroha_ffi_itm mut FfiStruct | ||
&T | ||
&mut T | ||
(A, B) | ||
(A, B, C) | ||
(A, B, C, D) | ||
(A, B, C, D, E) | ||
and 17 others | ||
= note: required because of the requirements on the impl of `COutPtr` for `IrVec<Vec<FfiStruct>, IrVec<FfiStruct, Opaque<FfiStruct>>>` | ||
= note: this error originates in the attribute macro `ffi_export` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.