You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Safety mistake? when calling binding function #232
It looks like create_reference is intended to set the pointer, so as long as the allocated pointer size is consistent and create_reference isn't trying to deref that pointer it seems ok. But thats and assumption, the code to create_reference should be checked.
But the cons arg is a raw pointer so theoretically some user can pass anything in there and then it can be safety issue because there is no check about validity of that pointer. Also checked napi docs but it doesn't say anything
It seems like there is a implicit conversion from ptr -> napi_ref that the lib should maybe make more explicit so any ptr can't be converted. If the creation of napi_ref was more protected, then it might be more secure to use the napi_ref. Is create_reference the only way to end up with a napi_ref?
It seems like there is a implicit conversion from ptr -> napi_ref that the lib should maybe make more explicit so any ptr can't be converted. If the creation of napi_ref was more protected, then it might be more secure to use the napi_ref. Is create_reference the only way to end up with a napi_ref?
I am looking into how to make it safe, also meanwhile working on temporary fix to segfault issue.
This kind of safety issue is everywhere in the library so seems like we would need to do big refactor to fix it.
Activity
digikata commentedon Sep 5, 2023
It looks like create_reference is intended to set the pointer, so as long as the allocated pointer size is consistent and create_reference isn't trying to deref that pointer it seems ok. But thats and assumption, the code to create_reference should be checked.
sehz commentedon Sep 5, 2023
macro
napi_call_resultalready encapsulates unsafe thus caller can avoid it. See https://doc.rust-lang.org/book/ch19-01-unsafe-rust.htmlozgrakkurt commentedon Sep 5, 2023
But the
consarg is a raw pointer so theoretically some user can pass anything in there and then it can be safety issue because there is no check about validity of that pointer. Also checked napi docs but it doesn't say anythingsehz commentedon Sep 5, 2023
I guess we can mark as unsafe
digikata commentedon Sep 5, 2023
It seems like there is a implicit conversion from ptr -> napi_ref that the lib should maybe make more explicit so any ptr can't be converted. If the creation of napi_ref was more protected, then it might be more secure to use the napi_ref. Is create_reference the only way to end up with a napi_ref?
ozgrakkurt commentedon Sep 6, 2023
I am looking into how to make it safe, also meanwhile working on temporary fix to segfault issue.
This kind of safety issue is everywhere in the library so seems like we would need to do big refactor to fix it.
For example this also seems unsafe to me:
node-bindgen/nj-core/src/basic.rs
Line 377 in 952a08a
not sure who has the ownership of the
Tvalue after this call