Dmitry Volyntsev [Fri, 24 May 2024 05:50:34 +0000 (22:50 -0700)]
Fetch: fixed heap-buffer-overflow in Headers.get().
Previously, when more than one header with the same name added to a
Headers object and Headers.get() was used to get the the duplicate
header heap-buffer-overflow occured. The overflow occurred due to an
incorrect calculation of the combined header value's length.
The issue was introduced in c43261bad627 (0.7.10).
Dmitry Volyntsev [Thu, 23 May 2024 06:08:15 +0000 (23:08 -0700)]
Fixed retval handling after an exception.
Previously, some functions set a retval too early. If this happened
before an exception a partially created object in inconsistent state
may be visible outside the affected functions.
The following functions were fixed:
Object.prototype.valueOf()
Array.prototype.toSpliced()
Array.prototype.toReversed()
Array.prototype.toSorted()
Dmitry Volyntsev [Mon, 20 May 2024 23:44:10 +0000 (16:44 -0700)]
HTTP: fixed handling of 0 length request body.
Previously, when r.requestBuffer was passed as a body argument to
ngx.fetch() or r.subrequest() then exception was thrown "Error: invalid
Request body" when the request body had 0 length.
Dmitry Volyntsev [Sat, 18 May 2024 04:54:50 +0000 (21:54 -0700)]
Change: removed byte strings API.
These functions are unsafe because they produce byte strings.
Byte strings may not work as expected with the existing JS methods.
The following functions were removed:
- njs_vm_value_string_set() use njs_vm_value_string_create() as a
drop-in replacement.
- njs_vm_value_string_alloc() use njs_chb_t and
njs_vm_value_string_create_chb() instead.
Previously, the function might fail to return the last part of the
compressed content. This problem is more visible when output size > 1024
or when chunkSize < the content size.
Modules: improved checking for duplicate js_set variables.
Since 6fb1aca4eeaf (0.8.4) the identical js_set variables introduced as
a part of an include file that is shared amongst multiple vhosts are
rejected during configuration parsing.
The patch ignores duplicate js_set variables when they refer to the same
JS function.
Make the test more robust against changes in nginx, specifically cf890df37bb6 (Stream: socket peek in preread phase).
The filter callbacks may be called multiple times by nginx and the exact
number is not specified. The new test avoids relying on the exact number
of calls from nginx.
Tests: adapt stream_js_preload_object.t to nginx changes.
Make the test more robust against changes in nginx, specifically cf890df37bb6 (Stream: socket peek in preread phase).
The filter callbacks may be called multiple times by nginx and the exact
number is not specified. The new test avoids relying on the exact number
of calls from nginx.
Dmitry Volyntsev [Fri, 19 Jan 2024 02:03:24 +0000 (18:03 -0800)]
Fixed tracking of unhandled rejected promises.
Checking for unhandled promise rejections while looping for pending jobs
produces false-positive reports when an rejected promised is handled
by one of the pending jobs later.
The fix is to check for unhandled promise rejections only at top level
calls like ngx_js_name_invoke() and ngx_js_name_call() and only after
all pending jobs are processed.
The issue was introduced in bc80bcb3102c (not released yet).
Fixed initialization of external prototypes with object entry.
When external was NULL (for example, when .u.object.properties is not
declared), an arithmetic operation was performed with NULL pointer which
is undefined behavior.
Fixed external values initialization in unit tests.
Since 0.8.0 modules can create their own constructors and prototypes.
A modules has two method: preinit() and init(). A module should
add its constructors and prototypes in preinit() and create its own
values in init(). Creating a value in preinit() results in an error.
The patch fixes the issue by creating an external value in init()
instead of preinit().
To align njs with other JS engines, async events are removed from njs
core. The following functions were removed: njs_vm_add_event(),
njs_vm_del_event(), njs_vm_waiting(). Instead the host is expected
to manage async events by itself.
In addition, the posted events are renamed to jobs, to better align with
the ECMA specs. The following methods are removed: njs_vm_run().
Instead, the host is expected to call njs_vm_execute_pending_job() in a
loop to execute pending jobs. The following functions were added:
njs_vm_enqueue_job().
Vadim Zhestikov [Thu, 30 Nov 2023 04:46:32 +0000 (20:46 -0800)]
Fixed memory over-read in njs_utf8_prev() and njs_utf8_next().
Previously, njs_utf8_next() might over-read up to 1 byte
beyond the string memory. Whereas njs_utf8_prev() might
over-read unlimited number of bytes before the string.