From 25b73a366f8b114d05add8b93aa52beb321dcb6e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 25 Mar 2022 12:29:54 +0100 Subject: fix(ext/ffi): enforce unstable check on ops (#14115) --- ext/ffi/lib.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'ext/ffi/lib.rs') diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 6ddeee51c..01aa17698 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -45,6 +45,11 @@ fn check_unstable(state: &OpState, api_name: &str) { } } +pub fn check_unstable2(state: &Rc>, api_name: &str) { + let state = state.borrow(); + check_unstable(&state, api_name) +} + pub trait FfiPermissions { fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError>; } @@ -144,8 +149,8 @@ pub fn init(unstable: bool) -> Extension { op_ffi_get_static::decl(), op_ffi_call::decl(), op_ffi_call_nonblocking::decl(), - op_ffi_call_ptr::decl(), - op_ffi_call_ptr_nonblocking::decl(), + op_ffi_call_ptr::decl::

(), + op_ffi_call_ptr_nonblocking::decl::

(), op_ffi_ptr_of::decl::

(), op_ffi_buf_copy_into::decl::

(), op_ffi_cstr_read::decl::

(), @@ -648,15 +653,38 @@ fn ffi_call(args: FfiCallArgs, symbol: &Symbol) -> Result { } #[op] -fn op_ffi_call_ptr(args: FfiCallPtrArgs) -> Result { +fn op_ffi_call_ptr( + state: &mut deno_core::OpState, + args: FfiCallPtrArgs, +) -> Result +where + FP: FfiPermissions + 'static, +{ + check_unstable(state, "Deno.UnsafeFnPointer#call"); + + let permissions = state.borrow_mut::(); + permissions.check(None)?; + let symbol = args.get_symbol(); ffi_call(args.into(), &symbol) } #[op] -async fn op_ffi_call_ptr_nonblocking( +async fn op_ffi_call_ptr_nonblocking( + state: Rc>, args: FfiCallPtrArgs, -) -> Result { +) -> Result +where + FP: FfiPermissions + 'static, +{ + check_unstable2(&state, "Deno.UnsafeFnPointer#call"); + + { + let mut state = state.borrow_mut(); + let permissions = state.borrow_mut::(); + permissions.check(None)?; + } + let symbol = args.get_symbol(); tokio::task::spawn_blocking(move || ffi_call(args.into(), &symbol)) .await @@ -774,6 +802,8 @@ fn op_ffi_ptr_of( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointer#of"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -788,6 +818,8 @@ fn op_ffi_buf_copy_into( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#copyInto"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -810,6 +842,8 @@ fn op_ffi_cstr_read( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getCString"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -825,6 +859,8 @@ fn op_ffi_read_u8( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getUint8"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -839,6 +875,8 @@ fn op_ffi_read_i8( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getInt8"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -853,6 +891,8 @@ fn op_ffi_read_u16( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getUint16"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -867,6 +907,8 @@ fn op_ffi_read_i16( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getInt16"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -881,6 +923,8 @@ fn op_ffi_read_u32( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getUint32"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -895,6 +939,8 @@ fn op_ffi_read_i32( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getInt32"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -909,6 +955,8 @@ fn op_ffi_read_u64( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getBigUint64"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -925,6 +973,8 @@ fn op_ffi_read_f32( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getFloat32"); + let permissions = state.borrow_mut::(); permissions.check(None)?; @@ -939,6 +989,8 @@ fn op_ffi_read_f64( where FP: FfiPermissions + 'static, { + check_unstable(state, "Deno.UnsafePointerView#getFloat64"); + let permissions = state.borrow_mut::(); permissions.check(None)?; -- cgit v1.2.3