Skip to content

fix null ptr #1126

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

Closed
wants to merge 1 commit into from
Closed

Conversation

xiaoshanlin000
Copy link

fix null ptr

fix null ptr
@saghul
Copy link
Contributor

saghul commented Jul 22, 2025

What code would trigger the null deref? A test would be great here!

@xiaoshanlin000
Copy link
Author

Using uv_fs_open , Random crash, if p is determined, it will not crash
if (req->result < 0) {
JSValue error = JS_NewError(ctx);
}

@saghul
Copy link
Contributor

saghul commented Jul 22, 2025

That's far from being a reproducible case. We run some very extensive testing with test262, so before applying a blind fix it would be good to have a script that creates a crash.

@xiaoshanlin000
Copy link
Author

It is really hard to reproduce. I debugged and tested it for a long time before it happened once.
2025-07-22_195806_254

@saghul
Copy link
Contributor

saghul commented Jul 22, 2025

Are you accessing the context from multiple threads by any chance?

@xiaoshanlin000
Copy link
Author

Use the libuv library to start a thread to execute uv_run and JS_ExecutePendingJob(rt, &ctx);

@saghul
Copy link
Contributor

saghul commented Jul 22, 2025

Do other threads use ctx? Note that if you use libuv's fs API aynchronously, the answer is "yes". If the answer is "yes", then you need to make sure to only access the JS engine from a single thread at a time, since it's not thread safe.

@xiaoshanlin000
Copy link
Author

Indeed, two threads are used, one is the test thread executing JS_Eval, so should I close this pull request?

@xiaoshanlin000
Copy link
Author

At the same time, I also used https://github.com/bellard/quickjs 2025-04-26 version, the same test file, the same two threads, one test thread and one uv thread, it does not have this problem. Is your code out of sync, or have you modified a lot of places?

@saghul
Copy link
Contributor

saghul commented Jul 23, 2025

Just a coincidence. The JS engine is not thread safe, you are going to run into big problems sooner or later.

@saghul saghul closed this Jul 23, 2025
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

Successfully merging this pull request may close these issues.

2 participants