1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(ext/node): limit OpState borrow in op_napi_open (#22151)

Fixes #22150
This commit is contained in:
Matt Mastracci 2024-01-27 12:17:15 -05:00 committed by GitHub
parent ed65bc6abc
commit bde2028d83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -479,15 +479,15 @@ pub unsafe fn weak_local(
#[op2] #[op2]
fn op_napi_open<NP, 'scope>( fn op_napi_open<NP, 'scope>(
scope: &mut v8::HandleScope<'scope>, scope: &mut v8::HandleScope<'scope>,
op_state: &mut OpState, op_state: Rc<RefCell<OpState>>,
#[string] path: String, #[string] path: String,
global: v8::Local<'scope, v8::Value>, global: v8::Local<'scope, v8::Value>,
) -> std::result::Result<v8::Local<'scope, v8::Value>, AnyError> ) -> std::result::Result<v8::Local<'scope, v8::Value>, AnyError>
where where
NP: NapiPermissions + 'static, NP: NapiPermissions + 'static,
{ {
let permissions = op_state.borrow_mut::<NP>(); // We must limit the OpState borrow because this function can trigger a
permissions.check(Some(&PathBuf::from(&path)))?; // re-borrow through the NAPI module.
let ( let (
async_work_sender, async_work_sender,
tsfn_sender, tsfn_sender,
@ -495,6 +495,9 @@ where
cleanup_hooks, cleanup_hooks,
tsfn_ref_counters, tsfn_ref_counters,
) = { ) = {
let mut op_state = op_state.borrow_mut();
let permissions = op_state.borrow_mut::<NP>();
permissions.check(Some(&PathBuf::from(&path)))?;
let napi_state = op_state.borrow::<NapiState>(); let napi_state = op_state.borrow::<NapiState>();
let isolate_ptr = op_state.borrow::<*mut v8::OwnedIsolate>(); let isolate_ptr = op_state.borrow::<*mut v8::OwnedIsolate>();
( (