diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-01-27 12:17:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-27 10:17:15 -0700 |
commit | bde2028d837cba3511df86ef7c67ee21eeb1ea0e (patch) | |
tree | c2985b48ba53689de16e36cd2e07fa1b362e28bd | |
parent | ed65bc6abc0a164ea68fae62e9a4e545f729be2d (diff) |
fix(ext/node): limit OpState borrow in op_napi_open (#22151)
Fixes #22150
-rw-r--r-- | ext/napi/lib.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 9b09467cd..520597891 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -479,15 +479,15 @@ pub unsafe fn weak_local( #[op2] fn op_napi_open<NP, 'scope>( scope: &mut v8::HandleScope<'scope>, - op_state: &mut OpState, + op_state: Rc<RefCell<OpState>>, #[string] path: String, global: v8::Local<'scope, v8::Value>, ) -> std::result::Result<v8::Local<'scope, v8::Value>, AnyError> where NP: NapiPermissions + 'static, { - let permissions = op_state.borrow_mut::<NP>(); - permissions.check(Some(&PathBuf::from(&path)))?; + // We must limit the OpState borrow because this function can trigger a + // re-borrow through the NAPI module. let ( async_work_sender, tsfn_sender, @@ -495,6 +495,9 @@ where cleanup_hooks, 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 isolate_ptr = op_state.borrow::<*mut v8::OwnedIsolate>(); ( |