Return value of JS_NewClass not checked in js_std_init/js_os_init

Open
#404 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
backend

Research direction

Start in quickjs-libc.c at the JS_NewClass calls in js_std_init and js_os_init, then read the JS_NewClass and JS_NewClass1 declarations to compare their return signatures. Reproduce the low-memory failure if possible and verify that both initialization paths handle class-registration failure before JS_SetClassProto is reached.

Written by the indexing model from the issue text.

Description

Hihi,

I am trying to debug crashes of quickjs in case of low memory settings. One of the problems I hit was

Assertion failed: (class_id < rt->class_count), function JS_SetClassProto, file quickjs.c, line 2208.

(which is here)

Turns out that this assertion is hit because the two JS_NewClass calls do not check the return value:

  1. https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/quickjs-libc.c#L1568
  2. https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/quickjs-libc.c#L3768

Do I understand this is a missing error check? Should I provide a PR to fix this? Is the error signature of JS_NewClass the same as JS_NewClass1?

Thanks!

Dominant language
C
Stars
11.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bellard/quickjs

All issues in bellard/quickjs

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.