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

Null pointer dereference in quick_js::bindings::OwnedObjectRef::property #122

Open
DarkRTA opened this issue Dec 31, 2021 · 3 comments
Open

Comments

@DarkRTA
Copy link

DarkRTA commented Dec 31, 2021

The following snippet of code causes a null pointer to be passed as the first argument of JS_GetPropertyStr, causing a null pointer dereference in JS_NewAtomLen

q::JS_GetPropertyStr(self.value.context.context, self.value.value, cname.as_ptr())

use quick_js::Context;

fn main() {
    let context = Context::new().unwrap();
    context.eval(r#"
(async function() {
    await new Promise((r,j)=>{for(let i = 0; i < 20; i++);})
})()
    "#).unwrap();
}
@DarkRTA DarkRTA changed the title Null pointer defererence in quick_js::bindings::OwnedObjectRef::property Null pointer dereference in quick_js::bindings::OwnedObjectRef::property Dec 31, 2021
@andrieshiemstra
Copy link
Contributor

Hi

This method will return or resolve to null because you don't return the result of your inner promise.. plus you don't resolve your inner promise so even if you return it the outer async func will never resolve..

do this...

(async function() {
    return await new Promise((r,j)=>{for(let i = 0; i < 20; i++) {}; r(123);})
})()

i only tested this in my own fork so no promises about this working in quickjs-rs

@DarkRTA
Copy link
Author

DarkRTA commented Dec 31, 2021

That's not the point. The point is that no code you run in the JS engine should cause memory safety issues, especially when this crash is caused by this crate and not quickjs itself.

I've tested this in the quickjs interpreter (outside of this crate) and it did not crash at all, so this is entirely an issue with the bindings.

@andrieshiemstra
Copy link
Contributor

Ah i see, well it's not really an issue with the bindings but with the wrapper.

I tried this with my own wrapper (which uses the bindings of this repo) and it neatly returns a never resolving Promise..

Sorry i can't be of more help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants