Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ext/napi/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,25 @@ 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,
isolate_ptr,
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>();
(
Expand Down
Loading