fix(napi): access violation in property getter/setter closure (#1552)

Signed-off-by: Markus <28785953+MarkusJx@users.noreply.github.com>
This commit is contained in:
Markus 2023-04-03 05:12:07 +02:00 committed by GitHub
parent f4f179c714
commit 71e44be73d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -1498,7 +1498,7 @@ pub(crate) unsafe extern "C" fn trampoline_setter<
let mut argc = 1;
let mut raw_args = vec![ptr::null_mut(); 1];
let mut raw_this = ptr::null_mut();
let mut closure_data_ptr = ptr::null_mut();
let mut data_ptr = ptr::null_mut();
let status = unsafe {
sys::napi_get_cb_info(
@ -1507,7 +1507,7 @@ pub(crate) unsafe extern "C" fn trampoline_setter<
&mut argc,
raw_args.as_mut_ptr(),
&mut raw_this,
&mut closure_data_ptr,
&mut data_ptr,
)
};
unsafe { raw_args.set_len(argc) };
@ -1515,6 +1515,8 @@ pub(crate) unsafe extern "C" fn trampoline_setter<
Status::from(status) == Status::Ok,
"napi_get_cb_info failed"
);
let closure_data_ptr = unsafe { *(data_ptr as *mut PropertyClosures) }.setter_closure;
(raw_args, raw_this, closure_data_ptr)
};
@ -1548,7 +1550,7 @@ pub(crate) unsafe extern "C" fn trampoline_getter<
) -> sys::napi_value {
let (raw_this, closure_data_ptr) = {
let mut raw_this = ptr::null_mut();
let mut closure_data_ptr = ptr::null_mut();
let mut data_ptr = ptr::null_mut();
let status = unsafe {
sys::napi_get_cb_info(
@ -1557,13 +1559,15 @@ pub(crate) unsafe extern "C" fn trampoline_getter<
&mut 0,
ptr::null_mut(),
&mut raw_this,
&mut closure_data_ptr,
&mut data_ptr,
)
};
debug_assert!(
Status::from(status) == Status::Ok,
"napi_get_cb_info failed"
);
let closure_data_ptr = unsafe { *(data_ptr as *mut PropertyClosures) }.getter_closure;
(raw_this, closure_data_ptr)
};

View file

@ -16,8 +16,8 @@ use crate::{sys, Callback, NapiRaw, Result};
#[cfg(feature = "napi5")]
#[derive(Copy, Clone)]
pub struct PropertyClosures {
setter_closure: *mut c_void,
getter_closure: *mut c_void,
pub setter_closure: *mut c_void,
pub getter_closure: *mut c_void,
}
#[cfg(feature = "napi5")]