]> git.kaiwu.me - njs.git/log
njs.git
3 years agoFixed large non-decimal literals.
Dmitry Volyntsev [Thu, 23 Jun 2022 06:37:16 +0000 (23:37 -0700)]
Fixed large non-decimal literals.

This closes #551 issue on Github.

3 years agoStream: throwing an exception when s.done() is used while filtering.
Dmitry Volyntsev [Thu, 23 Jun 2022 06:37:15 +0000 (23:37 -0700)]
Stream: throwing an exception when s.done() is used while filtering.

3 years agoAdded Symbol.for() and Symbol.keyfor().
Dmitry Volyntsev [Wed, 22 Jun 2022 04:54:14 +0000 (21:54 -0700)]
Added Symbol.for() and Symbol.keyfor().

3 years agoVersion bump.
Dmitry Volyntsev [Tue, 21 Jun 2022 22:29:00 +0000 (15:29 -0700)]
Version bump.

3 years agoAdded tag 0.7.5 for changeset 63c258c456ca
Dmitry Volyntsev [Tue, 21 Jun 2022 05:26:55 +0000 (22:26 -0700)]
Added tag 0.7.5 for changeset 63c258c456ca

3 years agoVersion 0.7.5. 0.7.5
Dmitry Volyntsev [Tue, 21 Jun 2022 04:38:49 +0000 (21:38 -0700)]
Version 0.7.5.

3 years agoFixed working with array-like object in Promise.all() and friends.
Dmitry Volyntsev [Fri, 17 Jun 2022 00:33:49 +0000 (17:33 -0700)]
Fixed working with array-like object in Promise.all() and friends.

Prevously, the code while iterating over an array-like object did not
take into account objects with absent elements.  As a result, the
resulting array object was returning with elements containing garbage
values.

The fix is to allocate and fill the resulting array object on the fly.

This closes #538 issue on Github.

3 years agoPropertly handling NJS_DECLINE in promise native functions.
Dmitry Volyntsev [Thu, 16 Jun 2022 00:10:39 +0000 (17:10 -0700)]
Propertly handling NJS_DECLINE in promise native functions.

Previously, NJS_DECLINE was returned from a Promise.all() and friends
when "resolve" property was not found in a promise constructor.
NJS_DECLINE was treated as NJS_ERROR in one place, but as NJS_OK in a
different place during the promise function evaluation.  As a result,
the VM was left in inconsistent state during stack unwinding which
resulted in a garbage return value.

The fix is to ensure that only NJS_ERROR or NJS_OK is returned
from ordinary native functions.

This closes #545 issue on Github.

3 years agoRenaming promise to promise_ctor to avoid confusion.
Dmitry Volyntsev [Wed, 15 Jun 2022 00:48:54 +0000 (17:48 -0700)]
Renaming promise to promise_ctor to avoid confusion.

3 years agoFixed njs_array_convert_to_slow_array().
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:49 +0000 (00:15 -0700)]
Fixed njs_array_convert_to_slow_array().

Previously, the function might free invalid pointer, as array->start is
not always points to the beginning of allocated memory block.

This closes #540 issue on Github.

3 years agoCatching invalid njs_mp_free() calls.
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:30 +0000 (00:15 -0700)]
Catching invalid njs_mp_free() calls.

3 years agoFixed memory freeing in njs_vm_compile().
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:29 +0000 (00:15 -0700)]
Fixed memory freeing in njs_vm_compile().

3 years agoRemoved njs_buffer_decode_destroy().
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:28 +0000 (00:15 -0700)]
Removed njs_buffer_decode_destroy().

3 years agoFixed njs_array_expand() for empty arrays.
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:28 +0000 (00:15 -0700)]
Fixed njs_array_expand() for empty arrays.

3 years agoFixed freeing of array created using njs_arr_create().
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:27 +0000 (00:15 -0700)]
Fixed freeing of array created using njs_arr_create().

3 years agoRemoved unused argument from njs_function_lambda_call().
Dmitry Volyntsev [Sat, 11 Jun 2022 07:15:20 +0000 (00:15 -0700)]
Removed unused argument from njs_function_lambda_call().

3 years agoFixed njs_iterator_to_array() with sparse arrays.
Dmitry Volyntsev [Thu, 9 Jun 2022 05:58:34 +0000 (22:58 -0700)]
Fixed njs_iterator_to_array() with sparse arrays.

This closes #524 issue on Github.

3 years agoFixed template literal from producing byte-strings.
Dmitry Volyntsev [Thu, 9 Jun 2022 04:06:16 +0000 (21:06 -0700)]
Fixed template literal from producing byte-strings.

Previously, as a side effect of creating a key for the values hash a
byte-string was created.  This byte-string was reused internally and
might appear in template literal.  As a result a byte-string was
produced as a value for a template literal.  Byte-strings are obsolete
and are scheduled for removal because they can cause issues with
internal routines not prepared for them.

3 years agoHTTP: returing undefined for Content-Type when the header is absent.
Dmitry Volyntsev [Wed, 8 Jun 2022 04:30:57 +0000 (21:30 -0700)]
HTTP: returing undefined for Content-Type when the header is absent.

This unifies empty response value type for r.headersOut.

3 years agoHTTP: fixed r.headersOut special getters when value is absent.
Dmitry Volyntsev [Tue, 7 Jun 2022 06:27:11 +0000 (23:27 -0700)]
HTTP: fixed r.headersOut special getters when value is absent.

Previously, when Content-Encoding or Content-Length header was absent,
an exception was thrown erroneously.

This closes #537 issue on Github.

3 years agoFixed String.prototype.replace() with byte strings.
Dmitry Volyntsev [Sat, 4 Jun 2022 06:24:12 +0000 (23:24 -0700)]
Fixed String.prototype.replace() with byte strings.

This closes #522 issue on Github.

3 years agoIntroduced njs_is_byte_or_ascii_string().
Dmitry Volyntsev [Sat, 4 Jun 2022 06:24:11 +0000 (23:24 -0700)]
Introduced njs_is_byte_or_ascii_string().

3 years agoImproved OPCODE debug by tracing native functions.
Dmitry Volyntsev [Sat, 4 Jun 2022 06:24:10 +0000 (23:24 -0700)]
Improved OPCODE debug by tracing native functions.

3 years agoFixed typed-array ctor when source array is changed while iterating.
Dmitry Volyntsev [Sat, 4 Jun 2022 06:24:08 +0000 (23:24 -0700)]
Fixed typed-array ctor when source array is changed while iterating.

Previously, the function used optimization for ordinary arrays with no
gaps (so called fast arrays).  For a fast array code took elements
directly from internal flat C array. The direct pointer may become
invalid as side-effect of custom valueOf() method for an element.

The fix is to eliminate the micro-optimization which uses direct
pointers.

The problem is similar to the 9578cc729205 (0.7.2) commit.

This closes #523 issue on Github.

3 years agoFixed njs_vmcode_interpreter() when await fails.
Dmitry Volyntsev [Thu, 2 Jun 2022 23:32:38 +0000 (16:32 -0700)]
Fixed njs_vmcode_interpreter() when await fails.

Previously, while interpreting a user function, njs_vmcode_interpreter()
might return prematurely when an error happens in await instruction.
This is not correct because the current frame has to be unwound (or
exception caught) first.

The fix is to exit through only 5 appropriate exit points to ensure
proper unwinding.

The patch correctly fixes issue reported in 07ef6c1f04f1 (0.7.3).

This closes #506 issue on Github.

3 years agoFixed function value initialization.
Dmitry Volyntsev [Thu, 2 Jun 2022 04:54:32 +0000 (21:54 -0700)]
Fixed function value initialization.

This closes #470 issue on Github.

3 years agoFixed catching of the exception thrown from an awaited function.
Dmitry Volyntsev [Wed, 1 Jun 2022 04:48:46 +0000 (21:48 -0700)]
Fixed catching of the exception thrown from an awaited function.

This closes #500 issue on Github.

3 years agoImproved OPCODE debug.
Dmitry Volyntsev [Wed, 1 Jun 2022 04:48:26 +0000 (21:48 -0700)]
Improved OPCODE debug.

3 years agoFixed typo in debug code introduced in 3e754413e907 (0.7.4).
Dmitry Volyntsev [Wed, 1 Jun 2022 04:48:19 +0000 (21:48 -0700)]
Fixed typo in debug code introduced in 3e754413e907 (0.7.4).

3 years agoHTTP: adapting to changes in nginx header structures.
Dmitry Volyntsev [Tue, 31 May 2022 16:26:47 +0000 (09:26 -0700)]
HTTP: adapting to changes in nginx header structures.

3 years agoHTTP: improved memory allocation error handling.
Sergey Kandaurov [Thu, 26 May 2022 11:28:06 +0000 (15:28 +0400)]
HTTP: improved memory allocation error handling.

3 years agoVersion bump.
Dmitry Volyntsev [Tue, 31 May 2022 15:53:18 +0000 (08:53 -0700)]
Version bump.

3 years agoAdded tag 0.7.4 for changeset b5198f7f11a3
Dmitry Volyntsev [Tue, 24 May 2022 16:10:52 +0000 (09:10 -0700)]
Added tag 0.7.4 for changeset b5198f7f11a3

3 years agoVersion 0.7.4. 0.7.4
Dmitry Volyntsev [Tue, 24 May 2022 16:07:58 +0000 (09:07 -0700)]
Version 0.7.4.

3 years agoTests: adapted WebCrypto tests to RHEL9.
Dmitry Volyntsev [Tue, 24 May 2022 05:26:51 +0000 (22:26 -0700)]
Tests: adapted WebCrypto tests to RHEL9.

3 years agoFixed use-of-uninitialized-value introduced in beb180165976.
Dmitry Volyntsev [Tue, 24 May 2022 05:26:50 +0000 (22:26 -0700)]
Fixed use-of-uninitialized-value introduced in beb180165976.

Found by Memory Sanitizer.

3 years agoFixed Object.prototype.constructor property handler with large heap.
Dmitry Volyntsev [Tue, 24 May 2022 05:26:35 +0000 (22:26 -0700)]
Fixed Object.prototype.constructor property handler with large heap.

Found by Memory Sanitizer.

3 years agoFixed redefinition of special props in Object.defineProperty().
Dmitry Volyntsev [Thu, 19 May 2022 23:41:08 +0000 (16:41 -0700)]
Fixed redefinition of special props in Object.defineProperty().

Previously, when NJS_PROPERTY_HANDLER property was updated it might be
left in inconsistent state.  Namely, prop->type was left unchanged, but
prop->value did not have an expected property handler.  As a result
consecutive reference to the property may result in a segment violation.

The fix is to update the prop->type during redefinition.

This closes #504 issue on Github.

3 years agoGetting rid of excessive NJS_LEVEL_TEMP.
Dmitry Volyntsev [Wed, 18 May 2022 07:01:05 +0000 (00:01 -0700)]
Getting rid of excessive NJS_LEVEL_TEMP.

3 years agoAdded generator debug.
Dmitry Volyntsev [Wed, 18 May 2022 06:26:09 +0000 (23:26 -0700)]
Added generator debug.

3 years agoImproved OPCODE debug.
Dmitry Volyntsev [Wed, 18 May 2022 06:26:05 +0000 (23:26 -0700)]
Improved OPCODE debug.

3 years agoFixed compatibility with BoringSSL.
Dmitry Volyntsev [Tue, 17 May 2022 05:57:27 +0000 (22:57 -0700)]
Fixed compatibility with BoringSSL.

The fix is to use more conventional API when dealing with HMAC
algorithm.

This closes #455 issue on Github.

4 years agoMaking function expression binding immutable according the specs.
Dmitry Volyntsev [Thu, 12 May 2022 04:08:21 +0000 (21:08 -0700)]
Making function expression binding immutable according the specs.

This closes #56 issue on Github.

4 years agoLeaving consistency checks as asserts for njs_scope_index().
Dmitry Volyntsev [Thu, 12 May 2022 00:51:17 +0000 (17:51 -0700)]
Leaving consistency checks as asserts for njs_scope_index().

4 years agoFixed ellipsis support.
Dmitry Volyntsev [Wed, 11 May 2022 23:33:46 +0000 (16:33 -0700)]
Fixed ellipsis support.

As of now, ellispis syntax is supported for function declaration with
the rest arguments.

This closes #365 issue on Github.

4 years agoFixed Array.prototype.fill() for typed-arrays.
Dmitry Volyntsev [Sat, 7 May 2022 01:55:35 +0000 (18:55 -0700)]
Fixed Array.prototype.fill() for typed-arrays.

This closes #478 issue on Github.

4 years agoFixed Object.defineProperty() when a recursive descriptor is provided.
Dmitry Volyntsev [Sat, 7 May 2022 01:55:07 +0000 (18:55 -0700)]
Fixed Object.defineProperty() when a recursive descriptor is provided.

This closes #481 issue on Github.

4 years agoImproved surrogate pairs support for PCRE2 backend.
Dmitry Volyntsev [Fri, 6 May 2022 03:25:05 +0000 (20:25 -0700)]
Improved surrogate pairs support for PCRE2 backend.

In collaboration with Javier Evans.

4 years agoFixed JSON.parse() when reviver function is provided.
Dmitry Volyntsev [Wed, 4 May 2022 23:44:48 +0000 (16:44 -0700)]
Fixed JSON.parse() when reviver function is provided.

This closes #480 issue on Github.

4 years agoImplement OrdinaryDelete() which does not throw exception.
Dmitry Volyntsev [Wed, 4 May 2022 23:23:46 +0000 (16:23 -0700)]
Implement OrdinaryDelete() which does not throw exception.

4 years agoAdded njs.version_number property.
Dmitry Volyntsev [Fri, 29 Apr 2022 00:59:03 +0000 (17:59 -0700)]
Added njs.version_number property.

4 years agoOptimising JSON.parse() for large objects.
Dmitry Volyntsev [Fri, 29 Apr 2022 00:49:59 +0000 (17:49 -0700)]
Optimising JSON.parse() for large objects.

4 years agoHTTP: expect escaped URIs in r.internalRedirect().
Dmitry Volyntsev [Fri, 29 Apr 2022 00:23:02 +0000 (17:23 -0700)]
HTTP: expect escaped URIs in r.internalRedirect().

Similarly to the nginx change in 975d7ab37b39 (1.17.2), we should accept
properly escaped URIs and unescape them as needed, else it is not possible
to handle URIs with question marks.

Previously, the URI was used as is.

4 years agoModules: added additional directives for Fetch API.
Dmitry Volyntsev [Thu, 28 Apr 2022 23:37:14 +0000 (16:37 -0700)]
Modules: added additional directives for Fetch API.

The following directives are added:
    * js_fetch_timeout
    * js_fetch_verify
    * js_fetch_buffer_size
    * js_fetch_max_response_buffer_size

This closes #489 issue on Github.

4 years agoFixed Array.prototype.lastIndexOf() with unicode string as "this".
Dmitry Volyntsev [Wed, 27 Apr 2022 23:31:00 +0000 (16:31 -0700)]
Fixed Array.prototype.lastIndexOf() with unicode string as "this".

Previously, when lastIndexOf() was called with unicode string as "this"
argument and a negative "fromIndex" argument null-pointer dererence
might occur because njs_string_offset() was called with invalid index
value whereas njs_string_offset() should always be called with valid
index argument.

The fix is to verify that from index is valid.

This closes #482 issue on Github.

4 years agoMaking FOREACH and NEXT instructions robust to invalid input.
Dmitry Volyntsev [Tue, 26 Apr 2022 23:07:06 +0000 (16:07 -0700)]
Making FOREACH and NEXT instructions robust to invalid input.

4 years agoFixed aggregation methods of Promise ctor with array-like object.
Dmitry Volyntsev [Tue, 26 Apr 2022 23:07:02 +0000 (16:07 -0700)]
Fixed aggregation methods of Promise ctor with array-like object.

Previously, while iterating over an array-like object the methods may be
resolved with INVALID values. INVALID value is a special internal type which
should never be visible by ordinary functions.

The fix is to ensure that absent elements are represented by undefined value.

The following methods were fixed Promise.all(), Promise.allSettled(),
    Promise.any(), Promise.race().

This closes #483 issue on Github.

4 years agoFixed Array.prototype.slice() with slow "this" argument.
Dmitry Volyntsev [Sat, 23 Apr 2022 00:02:36 +0000 (17:02 -0700)]
Fixed Array.prototype.slice() with slow "this" argument.

Previously, when "this" argument was not a fast array, but the "deleted" array
was a fast array, the "deleted" array may be left in uninitialized state if
"this" argument had gaps.

This fix is to ensure that "deleted" is properly initialized.

This fixes #485 issue on Github.

4 years agoFixed Array.prototype.sort() when arr size is changed in a comparator.
Dmitry Volyntsev [Sat, 23 Apr 2022 00:02:28 +0000 (17:02 -0700)]
Fixed Array.prototype.sort() when arr size is changed in a comparator.

This fixed #468 issue on Github.

4 years agoFixed Response headers iteration in Fetch API.
Dmitry Volyntsev [Thu, 14 Apr 2022 23:07:34 +0000 (16:07 -0700)]
Fixed Response headers iteration in Fetch API.

Previously, heap-use-after-free might occur when HTTP Response was
received with more than 8 headers and headers iteration is used.

The fix is not to assume that pointer to the beginning of the keys array
never changes.  The pointer may change when array is resized.

The issue was introduced in 81040de6b085 (0.5.1).

This closes #492 issue on Github.

4 years agoVersion bump
Dmitry Volyntsev [Thu, 14 Apr 2022 22:39:15 +0000 (15:39 -0700)]
Version bump

4 years agoAdded tag 0.7.3 for changeset f15d039cf625
Dmitry Volyntsev [Tue, 12 Apr 2022 04:26:35 +0000 (21:26 -0700)]
Added tag 0.7.3 for changeset f15d039cf625

4 years agoVersion 0.7.3. 0.7.3
Dmitry Volyntsev [Tue, 12 Apr 2022 04:22:32 +0000 (21:22 -0700)]
Version 0.7.3.

4 years agoFixed typo while calculating module path length.
Dmitry Volyntsev [Mon, 11 Apr 2022 22:55:14 +0000 (15:55 -0700)]
Fixed typo while calculating module path length.

The issue was introduced in 77c398f26d7e (not released yet).

4 years agoFixed njs_vmcode_interpreter() when "toString" conversion fails.
Dmitry Volyntsev [Mon, 28 Mar 2022 16:22:17 +0000 (16:22 +0000)]
Fixed njs_vmcode_interpreter() when "toString" conversion fails.

Previously, while interpreting a user function, njs_vmcode_interpreter()
might return prematurely when an error happens.  This is not correct
because the current frame has to be unwound (or exception caught)
first.

The fix is exit through only 5 appropriate exit points to ensure
proper unwinding.

This closes #467 issue on Github.

4 years agoTests: introduced OPCODE debug.
Dmitry Volyntsev [Tue, 22 Feb 2022 19:38:59 +0000 (19:38 +0000)]
Tests: introduced OPCODE debug.

4 years agoFixed allocation of large array literals.
Dmitry Volyntsev [Mon, 21 Feb 2022 16:53:16 +0000 (16:53 +0000)]
Fixed allocation of large array literals.

Previously, allocation of large array literals may result in
null-pointer dereference. The reason is that njs_array_alloc() may
return a slow array when size is large enough, but the instruction
code assumes that array is always flat.

The fix is to check fast_array flag before accessing array->start.

This closes #473 issue on Github.

4 years agoFixed frame allocation from an awaited frame.
Dmitry Volyntsev [Mon, 21 Feb 2022 16:52:59 +0000 (16:52 +0000)]
Fixed frame allocation from an awaited frame.

njs_function_frame_save() is used to save the awaited frame when "await"
instruction is encountered. The saving was done as a memcpy() of
existing runtime frame.

njs_function_frame_alloc() is used to alloc a new function frame, this
function tries to use a spare preallocated memory from the previous
frame first.  Previously, this function might result in "use-after-free"
when invoked from a restored frame saved with njs_function_frame_save().
Because njs_function_frame_save() left pointers to the spare memory of
the original frame which may be already free when saved frame is
restored.

The fix is to erase fields for the spare memory from the saved frame.

This closes #469 issue on Github.

4 years agoFixed Array.prototype.concat() when "this" is a slow array.
Dmitry Volyntsev [Mon, 21 Feb 2022 16:52:47 +0000 (16:52 +0000)]
Fixed Array.prototype.concat() when "this" is a slow array.

Previously, when the current appended element is fast array the "this"
array was expected to always be a fast array also.  This may not be the
case when the previous appended element was not fast thus converting
the "this" array to a slow form.

Previous fix introduced in 2c1382bab643 (0.7.2) was not complete, the
correct fix is to never assume "this" is fast, whereas njs_array_add()
may only be called with fast arrays.

This closes #471 issue in Github.

4 years agoRefactoring of user modules importing.
Dmitry Volyntsev [Mon, 21 Feb 2022 14:49:38 +0000 (14:49 +0000)]
Refactoring of user modules importing.

Previously, user modules were compiled as as anonymous functions in a
global scope.  This is incorrect, because modules should be compiled
in their own scope.

In addition, this patch introduces HostResolveImportedModule support.
When vm->options.ops->module_loader is provided, a module lookup
and compilation is delegated to this callback.

This closes #443 issue on Github.

4 years agoTests: splitting large import tests into several simple ones.
Dmitry Volyntsev [Tue, 15 Feb 2022 13:17:52 +0000 (13:17 +0000)]
Tests: splitting large import tests into several simple ones.

4 years agoIntroduced njs_parser_init().
Dmitry Volyntsev [Mon, 14 Feb 2022 14:10:59 +0000 (14:10 +0000)]
Introduced njs_parser_init().

4 years agoFixed Function constructor in CLI.
Dmitry Volyntsev [Mon, 14 Feb 2022 14:10:47 +0000 (14:10 +0000)]
Fixed Function constructor in CLI.

Previously, Function constructor exported its local variables to
vm->variables_hash. vm->variables_hash is used in njs CLI to query
global variables during console input completion.  The exporting is
incorrect because it pollutes the global scope.

4 years agoFixed backtraces for native modules imported with import statement.
Dmitry Volyntsev [Mon, 14 Feb 2022 14:10:26 +0000 (14:10 +0000)]
Fixed backtraces for native modules imported with import statement.

Previously, the module name was missing when exception is reported
for a native module function imported with import statement.

4 years agoFixed backtraces while traversing imported user modules.
Dmitry Volyntsev [Mon, 14 Feb 2022 14:10:04 +0000 (14:10 +0000)]
Fixed backtraces while traversing imported user modules.

Previously, njs_builtin_match_native_function(), which is used to build a
backtrace for an exception, assumed that user modules always return
object values, which is not the case.  As a result, njs_object_traverse()
may receive incorrect pointer.

This fix is to only traverse object values.

4 years agoTests: refactored modules tests using test262 test suite.
Dmitry Volyntsev [Thu, 27 Jan 2022 13:01:55 +0000 (13:01 +0000)]
Tests: refactored modules tests using test262 test suite.

4 years agoTests: added support for proper negative test262 tests.
Dmitry Volyntsev [Wed, 26 Jan 2022 17:24:58 +0000 (17:24 +0000)]
Tests: added support for proper negative test262 tests.

4 years agoTypes: added async/await support for TS files.
Jakub Jirutka [Wed, 26 Jan 2022 01:44:18 +0000 (02:44 +0100)]
Types: added async/await support for TS files.

Since 0.7.0 async/await support was added.

This closes #461 issue on Github.

4 years agoShell: added options for custom exit failure code.
Dmitry Volyntsev [Wed, 26 Jan 2022 17:24:57 +0000 (17:24 +0000)]
Shell: added options for custom exit failure code.

4 years agoVersion bump.
Dmitry Volyntsev [Tue, 25 Jan 2022 19:06:58 +0000 (19:06 +0000)]
Version bump.

4 years agoAdded tag 0.7.2 for changeset 3dd315b80bab
Dmitry Volyntsev [Tue, 25 Jan 2022 13:38:25 +0000 (13:38 +0000)]
Added tag 0.7.2 for changeset 3dd315b80bab

4 years agoVersion 0.7.2. 0.7.2
Dmitry Volyntsev [Tue, 25 Jan 2022 13:37:45 +0000 (13:37 +0000)]
Version 0.7.2.

4 years agoFixed function redeclaration.
Dmitry Volyntsev [Tue, 25 Jan 2022 13:18:20 +0000 (13:18 +0000)]
Fixed function redeclaration.

Previously, the existing lambda structure was reused resulting in the
properties of the previously defined function was merged into a new one.

The bug was introduced in 66bd2cc7fd87 (0.7.0).

4 years agoFixed recursive async function calls.
Dmitry Volyntsev [Fri, 21 Jan 2022 14:31:30 +0000 (14:31 +0000)]
Fixed recursive async function calls.

Previously, PromiseCapability record was stored (function->context)
directly in function object during a function invocation.  This is
not correct, because PromiseCapability record should be linked to
current execution context.  As a result, function->context is
overwritten with consecutive recursive calls which results in
use-after-free.

This closes #451 issue on Github.

4 years agoFixed Function.prototype.apply() with slow arrays.
Dmitry Volyntsev [Wed, 19 Jan 2022 14:03:49 +0000 (14:03 +0000)]
Fixed Function.prototype.apply() with slow arrays.

Previously, the function had two issues:
   * array->start was referenced without checking for fast array flag
   * the created arguments list was not sanity-checked for its length,
     which can be very large.

The fix is to remove micro-optimization for arrays and introduce limit
size for arguments list.

This closes #449 issue in Github.

4 years agoFixed type confusion bug while resolving promises.
Dmitry Volyntsev [Wed, 19 Jan 2022 13:12:09 +0000 (13:12 +0000)]
Fixed type confusion bug while resolving promises.

Previously, the internal function njs_promise_perform_then() which
implements PerformPromiseThen() expects its first argument to always be
a promise instance.  This assertion might be invalid because the
functions corresponding to Promise.prototype.then() and
Promise.resolve() incorrectly verified their arguments.

Specifically, the functions recognized their first argument as promise
if it was an object which was an Promise or had Promise object in its
prototype chain.  The later condition is not correct because internal
slots are not inherited according to the spec.

This closes #447 issue in Github.

4 years agoImproved access to this argument.
Dmitry Volyntsev [Tue, 18 Jan 2022 15:37:11 +0000 (15:37 +0000)]
Improved access to this argument.

'this' argument is always present, so it may be accessed
without checking the number provided arguments.

4 years agoFixed Buffer.concat() with subarrays.
Sylvain Etienne [Tue, 18 Jan 2022 07:37:09 +0000 (08:37 +0100)]
Fixed Buffer.concat() with subarrays.

This closes #458 issue on Github.

4 years ago2022 year.
Dmitry Volyntsev [Tue, 18 Jan 2022 15:36:40 +0000 (15:36 +0000)]
2022 year.

4 years agoFixed Array.prototype.concat() with exotic argument object.
Dmitry Volyntsev [Tue, 18 Jan 2022 15:35:00 +0000 (15:35 +0000)]
Fixed Array.prototype.concat() with exotic argument object.

The issue was introduced in 2c1382bab643.

4 years agoFixed Array.prototype.reverse() when array is changed while iterating.
Dmitry Volyntsev [Fri, 14 Jan 2022 14:40:27 +0000 (14:40 +0000)]
Fixed Array.prototype.reverse() when array is changed while iterating.

Previously, the flat array may be converted to a slow one as a
side-effect of a custom getter invocation for a proto array object.
The function erroneously assumed that the this array remains flat
while iterating.

The fix is to eliminate the micro-optimization which uses direct
pointers.

The problem is similar to the previous commits.

4 years agoSimplified element access in Array.prototype.shift().
Dmitry Volyntsev [Thu, 13 Jan 2022 18:30:31 +0000 (18:30 +0000)]
Simplified element access in Array.prototype.shift().

Previously, array structure may be left in inconsistent state
when a custom getter in a proto array changes array size.

The change is similar to the previous commits.

4 years agoSimplified element access in Array.prototype.pop().
Dmitry Volyntsev [Thu, 13 Jan 2022 18:30:31 +0000 (18:30 +0000)]
Simplified element access in Array.prototype.pop().

The change is similar to the previous commits.

4 years agoFixed Array.prototype.concat() when array is changed while iterating.
Dmitry Volyntsev [Thu, 13 Jan 2022 16:20:58 +0000 (16:20 +0000)]
Fixed Array.prototype.concat() when array is changed while iterating.

Previously, the flat array may be converted to a slow one as a
side-effect of a custom getter invocation for a proto array object.
The function erroneously assumed that the this array remains flat
while iterating.

The fix is to eliminate the micro-optimization which uses direct
pointers.

The problem is similar to the previous commits.

4 years agoFixed Array.prototype.slice() when array is changed while iterating.
Dmitry Volyntsev [Thu, 13 Jan 2022 15:59:08 +0000 (15:59 +0000)]
Fixed Array.prototype.slice() when array is changed while iterating.

Previously, the flat array may be converted to a slow one as a
side-effect of a custom getter invocation for a proto array object.
The function erroneously assumed that the this array remains flat
while iterating.

The fix is to eliminate the micro-optimization which uses direct
pointers.

The problem is similar to the previous (9578cc729205) commit.

This closes #445 issue on Github.

4 years agoFixed Array.prototype.join() when array is changed while iterating.
Dmitry Volyntsev [Wed, 12 Jan 2022 17:59:42 +0000 (17:59 +0000)]
Fixed Array.prototype.join() when array is changed while iterating.

Previously, the function used optimization for ordinary arrays with no
gaps (so called fast arrays).  For a fast array code took elements
directly from internal flat C array. The direct pointer may become
invalid as side-effect of custom toString() method for an element.

Specifically, the pointer was passed directly to
njs_value_to_primitive() which attempts to call toString() followed by
valueOf().  When the array size is changed as a side-effect of
toString() and not a string value is returned by toString() the pointer
becomes invalid and is passed to valueOf() which causes use-after-free.

The fix is to eliminate the micro-optimization which uses direct pointers.

Found by PolyGlot fuzzing framework.

This closes #444 issue on Github.

4 years agoMaking njs_value_property_i64() and njs_value_property_i64_set() fast.
Dmitry Volyntsev [Wed, 12 Jan 2022 17:58:19 +0000 (17:58 +0000)]
Making njs_value_property_i64() and njs_value_property_i64_set() fast.

Since f5afb325896f (0.3.9) njs_value_property() and
njs_value_property_set() have fast paths when key is a number.

Passing key as a number eliminates conversion index to string and back.

4 years agoRemoving MSAN unpoison workarounds for clang-9 and below.
Dmitry Volyntsev [Wed, 12 Jan 2022 17:58:18 +0000 (17:58 +0000)]
Removing MSAN unpoison workarounds for clang-9 and below.

MSAN unpoison workaround was introduced in 13dbdff9b76f (0.3.9) for a
false-positive bug in clang-9 and below.

Also, after 80d95b2881f6 (0.4.1) the bug is not triggered anymore.

4 years agoFixed fuzzing target bug introduced in 4d4657128baf (0.7.1).
Dmitry Volyntsev [Tue, 11 Jan 2022 13:02:33 +0000 (13:02 +0000)]
Fixed fuzzing target bug introduced in 4d4657128baf (0.7.1).

Previously, njs_process_script() took vm pointer from console object,
but after 4d4657128baf the object is not initialized in
LLVMFuzzerTestOneInput().

The fix is to always pass vm pointer explicitly.

This also closes #456 issue on Github.

4 years agoImproved discovery of OpenSSL libraries.
Dmitry Volyntsev [Wed, 29 Dec 2021 18:26:40 +0000 (18:26 +0000)]
Improved discovery of OpenSSL libraries.

Trying to link again the library using --cc-opt and --ld-opt before
attempting to use the default.

This change is similar to 9e2e4d04dfc4 (0.7.1) made for PCRE.