]> git.kaiwu.me - njs.git/log
njs.git
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.

4 years agoConfigure: added --build-dir option.
Dmitry Volyntsev [Wed, 29 Dec 2021 17:20:09 +0000 (17:20 +0000)]
Configure: added --build-dir option.

4 years agoTests: fixed "fs" tests with custom build directory.
Dmitry Volyntsev [Wed, 29 Dec 2021 17:19:55 +0000 (17:19 +0000)]
Tests: fixed "fs" tests with custom build directory.

4 years agoConfigure: fixed custom NJS_BUILD_DIR values support.
Dmitry Volyntsev [Wed, 29 Dec 2021 16:56:47 +0000 (16:56 +0000)]
Configure: fixed custom NJS_BUILD_DIR values support.

The issue was introduced in 4d4657128baf (0.7.1).

This closes #454 issue on Github.

4 years agoAdded description for recently added configure options.
Dmitry Volyntsev [Wed, 29 Dec 2021 16:03:13 +0000 (16:03 +0000)]
Added description for recently added configure options.

4 years agoTypes: added TS definitions for fs.stat() and fs.lstat() methods.
Dmitry Volyntsev [Wed, 29 Dec 2021 16:03:12 +0000 (16:03 +0000)]
Types: added TS definitions for fs.stat() and fs.lstat() methods.

4 years agoVersion bump.
Dmitry Volyntsev [Wed, 29 Dec 2021 16:03:11 +0000 (16:03 +0000)]
Version bump.

4 years agoAdded tag 0.7.1 for changeset 35aca5cc5ea7
Dmitry Volyntsev [Tue, 28 Dec 2021 14:24:53 +0000 (14:24 +0000)]
Added tag 0.7.1 for changeset 35aca5cc5ea7

4 years agoVersion 0.7.1. 0.7.1
Dmitry Volyntsev [Tue, 28 Dec 2021 13:55:44 +0000 (13:55 +0000)]
Version 0.7.1.

4 years agoFixed information leak in Buffer.from().
Artem S. Povalyukhin [Sat, 25 Dec 2021 19:45:30 +0000 (22:45 +0300)]
Fixed information leak in Buffer.from().

This closes #446 on Github.

4 years agoImproved Buffer.from() with Buffer-like objects.
Artem S. Povalyukhin [Sat, 25 Dec 2021 19:45:30 +0000 (22:45 +0300)]
Improved Buffer.from() with Buffer-like objects.

4 years agoAdded missing element in typeof table for DataView() type.
Artem S. Povalyukhin [Fri, 24 Dec 2021 07:00:15 +0000 (10:00 +0300)]
Added missing element in typeof table for DataView() type.

Previously, typeof operation for DataView object resulted
in out of bounds array accessing.

This fixes #450 issue on Github.

4 years agoImproved discovery of PCRE libraries.
Dmitry Volyntsev [Fri, 24 Dec 2021 16:54:12 +0000 (16:54 +0000)]
Improved discovery of PCRE libraries.

Trying to link again the library using --cc-opt and --ld-opt before
attempting to use pcre-config or pcre2-config.

4 years agoPassing --ld-opt flags while linking.
Dmitry Volyntsev [Fri, 24 Dec 2021 15:48:12 +0000 (15:48 +0000)]
Passing --ld-opt flags while linking.

4 years agoBuilding regexp backend as an external.
Dmitry Volyntsev [Fri, 24 Dec 2021 15:48:11 +0000 (15:48 +0000)]
Building regexp backend as an external.

This allows not to build PCRE specific code as a part of libnjs.a thus
supporting nginx builds with flags like --with-pcre=PCRE_DIR.  When
--no-pcre configure option is provided external code have to implement
methods declared in njs_regex.h.

This also closes #18 issue on Github.

4 years agoAdding module suffix for njs module files.
Dmitry Volyntsev [Fri, 24 Dec 2021 15:48:09 +0000 (15:48 +0000)]
Adding module suffix for njs module files.

4 years agoIntroducing --no-openssl to disable OpenSSL discover.
Dmitry Volyntsev [Fri, 24 Dec 2021 15:48:09 +0000 (15:48 +0000)]
Introducing --no-openssl to disable OpenSSL discover.

4 years agoTests: added help info for test262.
Dmitry Volyntsev [Fri, 24 Dec 2021 15:48:08 +0000 (15:48 +0000)]
Tests: added help info for test262.

4 years agoFixed 1-byte memory over-read introduced in previous commit.
Dmitry Volyntsev [Thu, 23 Dec 2021 14:28:12 +0000 (14:28 +0000)]
Fixed 1-byte memory over-read introduced in previous commit.

sizeof("\0") returns 2 because of the implicit zero byte added at
the end of string literals. Instead njs_length() was intended to be
used.

4 years agoImproved njs_ftw().
Dmitry Volyntsev [Thu, 23 Dec 2021 13:30:44 +0000 (13:30 +0000)]
Improved njs_ftw().

Replacing strcpy() with memcpy() as the former is considered
insecure.

Found by Clang static analyzer.

4 years agoTests: fixed fs/methods.t.ts on RHEL8.
Dmitry Volyntsev [Wed, 22 Dec 2021 17:22:14 +0000 (17:22 +0000)]
Tests: fixed fs/methods.t.ts on RHEL8.

4 years agoTests: improved test262 output when a test fails.
Dmitry Volyntsev [Wed, 22 Dec 2021 16:54:27 +0000 (16:54 +0000)]
Tests: improved test262 output when a test fails.

4 years agoFixed WebCrypto sign() and verify() methods with OpenSSL 3.0.1.
Dmitry Volyntsev [Wed, 22 Dec 2021 16:54:13 +0000 (16:54 +0000)]
Fixed WebCrypto sign() and verify() methods with OpenSSL 3.0.1.

Since 3.0.1 EVP_DigestSignFinal() expects siglen to contain the
actual buffer size for signature buffer.

4 years agoAdded missed njs_parser_failed() in njs_parser_module_lambda_after().
Zhidao HONG [Wed, 22 Dec 2021 02:50:16 +0000 (10:50 +0800)]
Added missed njs_parser_failed() in njs_parser_module_lambda_after().

4 years agoAdded missed static declarations.
Zhidao HONG [Wed, 22 Dec 2021 02:50:16 +0000 (10:50 +0800)]
Added missed static declarations.

4 years agoFixed OpenSSL detection support when Address Sanitizer is enabled.
Dmitry Volyntsev [Wed, 22 Dec 2021 16:54:05 +0000 (16:54 +0000)]
Fixed OpenSSL detection support when Address Sanitizer is enabled.

4 years agoRefactor modules using external prototypes.
Dmitry Volyntsev [Tue, 21 Dec 2021 17:42:26 +0000 (17:42 +0000)]
Refactor modules using external prototypes.

4 years agoRenaming njs_module_t -> njs_mod_t.
Dmitry Volyntsev [Tue, 21 Dec 2021 15:49:21 +0000 (15:49 +0000)]
Renaming njs_module_t -> njs_mod_t.

4 years agoTests: moving module tests into separate test suites.
Dmitry Volyntsev [Tue, 21 Dec 2021 15:49:13 +0000 (15:49 +0000)]
Tests: moving module tests into separate test suites.

4 years agoTests: moving backtraces test into a separate test suite.
Dmitry Volyntsev [Tue, 21 Dec 2021 15:49:05 +0000 (15:49 +0000)]
Tests: moving backtraces test into a separate test suite.

4 years agoAdded constructor flag for methods in external prototypes.
Dmitry Volyntsev [Tue, 21 Dec 2021 15:48:45 +0000 (15:48 +0000)]
Added constructor flag for methods in external prototypes.

4 years agoModules: removed dead code left after dfcbfb5e27b2.
Dmitry Volyntsev [Tue, 14 Dec 2021 20:14:23 +0000 (20:14 +0000)]
Modules: removed dead code left after dfcbfb5e27b2.

Found by Coverity (CID 1495259).

4 years agoChecking cwd path length in njs_module_relative_path().
Dmitry Volyntsev [Tue, 14 Dec 2021 20:06:23 +0000 (20:06 +0000)]
Checking cwd path length in njs_module_relative_path().

4 years agoUsing njs_arr_item() when accessing vm->protos elements.
Dmitry Volyntsev [Tue, 14 Dec 2021 14:08:12 +0000 (14:08 +0000)]
Using njs_arr_item() when accessing vm->protos elements.

4 years agoModules: removed "js_include" directive deprecated in 0.4.0.
Dmitry Volyntsev [Thu, 9 Dec 2021 14:38:40 +0000 (14:38 +0000)]
Modules: removed "js_include" directive deprecated in 0.4.0.

4 years agoGenerator: removing njs_generate_children_indexes_release_pop().
Dmitry Volyntsev [Wed, 8 Dec 2021 13:14:59 +0000 (13:14 +0000)]
Generator: removing njs_generate_children_indexes_release_pop().

4 years agoGenerator: introduced njs_generator_init().
Dmitry Volyntsev [Wed, 8 Dec 2021 13:14:58 +0000 (13:14 +0000)]
Generator: introduced njs_generator_init().

4 years agoGenerator: fixed typo introduced in efdc5f18195e (0.6.2).
Dmitry Volyntsev [Wed, 8 Dec 2021 13:14:56 +0000 (13:14 +0000)]
Generator: fixed typo introduced in efdc5f18195e (0.6.2).

4 years agoTests: improved unit tests after efdc5f18195e (0.6.2).
Dmitry Volyntsev [Tue, 7 Dec 2021 19:42:27 +0000 (19:42 +0000)]
Tests: improved unit tests after efdc5f18195e (0.6.2).

In efdc5f18195e the recursion was removed from generator,
therefore tests that are not limited by system stack should always
pass.

4 years agoFixed function redeclaration in CLI when interactive mode is on.
Dmitry Volyntsev [Tue, 7 Dec 2021 13:15:19 +0000 (13:15 +0000)]
Fixed function redeclaration in CLI when interactive mode is on.

The issue was introduced in 0a2a0b5a74f4 (0.6.0).

4 years agoFixed execution of async function in synchronous context.
Dmitry Volyntsev [Fri, 3 Dec 2021 13:55:22 +0000 (13:55 +0000)]
Fixed execution of async function in synchronous context.

The bug was introduced in 92d10cd761e2 (0.7.0).

4 years agoTests: added promise support for unit tests subrequest method.
Dmitry Volyntsev [Fri, 3 Dec 2021 13:55:12 +0000 (13:55 +0000)]
Tests: added promise support for unit tests subrequest method.

4 years agoAdded memory exception if alloc fails for njs_vm_function_alloc.
Dmitry Volyntsev [Fri, 3 Dec 2021 13:55:11 +0000 (13:55 +0000)]
Added memory exception if alloc fails for njs_vm_function_alloc.

4 years agoFixed catching of exception thrown in try block of async function.
Dmitry Volyntsev [Tue, 30 Nov 2021 14:55:57 +0000 (14:55 +0000)]
Fixed catching of exception thrown in try block of async function.

The bug was introduced in 92d10cd761e2 (0.7.0).

4 years agoTests: making async/await test filenames shorter.
Dmitry Volyntsev [Mon, 29 Nov 2021 18:14:25 +0000 (18:14 +0000)]
Tests: making async/await test filenames shorter.

4 years agoTests: refactored JavaScript tests.
Dmitry Volyntsev [Mon, 29 Nov 2021 16:50:41 +0000 (16:50 +0000)]
Tests: refactored JavaScript tests.

A generic runner test/run is introduced.  It runs all available tests
in test/ directory.  JavaScript files are expected to be compliant with
Test262.

4 years agoAllowing to build njs util without interactive shell support.
Dmitry Volyntsev [Mon, 29 Nov 2021 14:41:09 +0000 (14:41 +0000)]
Allowing to build njs util without interactive shell support.

4 years agoFixed building unit tests binaries on MacOS with custom LDFLAGS.
Dmitry Volyntsev [Mon, 29 Nov 2021 14:05:33 +0000 (14:05 +0000)]
Fixed building unit tests binaries on MacOS with custom LDFLAGS.

4 years agoFixed exception throwing when RegExp match fails.
Dmitry Volyntsev [Mon, 22 Nov 2021 13:37:11 +0000 (13:37 +0000)]
Fixed exception throwing when RegExp match fails.

The issue was introduced in a83775113025 (0.1.15).

This closes #439 issue on Github.

4 years agoUpdated README with the reference to njs-examples repo.
Dmitry Volyntsev [Thu, 18 Nov 2021 13:48:55 +0000 (13:48 +0000)]
Updated README with the reference to njs-examples repo.

4 years agoFixed build with OpenSSL 3.0 built with no-deprecated.
Sergey Kandaurov [Wed, 17 Nov 2021 16:14:19 +0000 (19:14 +0300)]
Fixed build with OpenSSL 3.0 built with no-deprecated.

This covers deprecated OpenSSL_add_all_algorithms() and RSA/EC_KEY types.

4 years agoSSL: fixed reporting of the detected library version.
Dmitry Volyntsev [Wed, 17 Nov 2021 17:01:07 +0000 (17:01 +0000)]
SSL: fixed reporting of the detected library version.

Previously, `openssl version` command was used to report the OpenSSL
version.  Whereas, when provided with custom CFLAGS and LDFLAGS the
used library may differ from the system one.

The fix is to report OpenSSL version using the provided library.

4 years agoFixed WebCrypto sign() and verify() methods with OpenSSL 3.0.
Dmitry Volyntsev [Wed, 17 Nov 2021 14:11:28 +0000 (14:11 +0000)]
Fixed WebCrypto sign() and verify() methods with OpenSSL 3.0.

4 years agoIntroduced PCRE2 RegExp backend.
Dmitry Volyntsev [Thu, 11 Nov 2021 14:27:15 +0000 (14:27 +0000)]
Introduced PCRE2 RegExp backend.

4 years agoRegExp: improved source string treatment.
Dmitry Volyntsev [Thu, 11 Nov 2021 14:26:41 +0000 (14:26 +0000)]
RegExp: improved source string treatment.

Previously, njs_regexp_pattern_create() in addition to a pattern
compilation made a string representation for a RegExp which was returned
by RegExp.prototype.toString() as is.

After 02444445df29 (0.6.0), RegExp.prototype.toString() was implemented
according to the spec, and since then it creates a RegExp string on the fly.

This patch removes the extra code which was left.

In addition, as a source string may not be a valid UTF-8 string (in
RegExp literals), RegExp.prototype.toString() now ensures that a
valid UTF-8 string is returned.

4 years agoRegExp: incapsulating PCRE API.
Dmitry Volyntsev [Thu, 11 Nov 2021 14:26:30 +0000 (14:26 +0000)]
RegExp: incapsulating PCRE API.

4 years agoTests: adapting fs tests introduced in 685adce92af1 for various OS.
Dmitry Volyntsev [Wed, 10 Nov 2021 14:50:16 +0000 (14:50 +0000)]
Tests: adapting fs tests introduced in 685adce92af1 for various OS.

4 years agoRemoved unused regular expression API.
Dmitry Volyntsev [Tue, 9 Nov 2021 17:59:58 +0000 (17:59 +0000)]
Removed unused regular expression API.

4 years agoPCRE: removed unused context functions.
Dmitry Volyntsev [Tue, 9 Nov 2021 17:59:46 +0000 (17:59 +0000)]
PCRE: removed unused context functions.

4 years agoAdded fs.Stats, fs.stat() and friends.
Dmitry Volyntsev [Wed, 3 Nov 2021 15:46:15 +0000 (15:46 +0000)]
Added fs.Stats, fs.stat() and friends.

4 years agoAdded njs_date_alloc().
Dmitry Volyntsev [Tue, 2 Nov 2021 12:38:42 +0000 (12:38 +0000)]
Added njs_date_alloc().

4 years agoUnified creation of objects with custom value slots.
Dmitry Volyntsev [Tue, 2 Nov 2021 12:38:02 +0000 (12:38 +0000)]
Unified creation of objects with custom value slots.

4 years agoSimplified object dumping.
Dmitry Volyntsev [Tue, 2 Nov 2021 12:37:19 +0000 (12:37 +0000)]
Simplified object dumping.

4 years agoGetting rid of special types for primitive objects.
Dmitry Volyntsev [Tue, 2 Nov 2021 12:37:00 +0000 (12:37 +0000)]
Getting rid of special types for primitive objects.

The following types were removed: NJS_OBJECT_BOOLEAN,
NJS_OBJECT_NUMBER, NJS_OBJECT_SYMBOL, NJS_OBJECT_STRING.

Instead a generic NJS_OBJECT_VALUE type is used for objects
with custom slots.

4 years agoTests: refactored "fs" module tests.
Dmitry Volyntsev [Tue, 2 Nov 2021 12:35:34 +0000 (12:35 +0000)]
Tests: refactored "fs" module tests.

4 years agoTests: allowing to define own test function per test suite.
Dmitry Volyntsev [Mon, 1 Nov 2021 15:53:30 +0000 (15:53 +0000)]
Tests: allowing to define own test function per test suite.

4 years agoFixed heap-use-after-free in await frame.
Alexander Borisov [Mon, 1 Nov 2021 15:32:48 +0000 (18:32 +0300)]
Fixed heap-use-after-free in await frame.

The bug was introduced in 92d10cd761e2 (0.7.0).

4 years agoFixed decodeURI() and decodeURIComponent() with invalid byte strings.
Dmitry Volyntsev [Fri, 29 Oct 2021 13:57:26 +0000 (13:57 +0000)]
Fixed decodeURI() and decodeURIComponent() with invalid byte strings.

The issue was introduced in 855edd76bdb6 (0.4.3).

This closes #435 issue on Github.

4 years agoRemoved surplus condition from Base64 decoded length counting.
Valentin Bartenev [Tue, 26 Oct 2021 13:14:07 +0000 (16:14 +0300)]
Removed surplus condition from Base64 decoded length counting.

4 years agoStream: fixed build without --with-http_ssl_module.
Dmitry Volyntsev [Wed, 20 Oct 2021 13:01:55 +0000 (13:01 +0000)]
Stream: fixed build without --with-http_ssl_module.

This closes #434 issue on Github.

4 years agoVersion bump.
Dmitry Volyntsev [Wed, 20 Oct 2021 12:16:37 +0000 (12:16 +0000)]
Version bump.

4 years agoAdded tag 0.7.0 for changeset 8418bd4a4ce3
Dmitry Volyntsev [Tue, 19 Oct 2021 12:54:08 +0000 (12:54 +0000)]
Added tag 0.7.0 for changeset 8418bd4a4ce3

4 years agoVersion 0.7.0. 0.7.0
Dmitry Volyntsev [Tue, 19 Oct 2021 12:24:13 +0000 (12:24 +0000)]
Version 0.7.0.

4 years agoModules: fixed Respose.headers getter in fetch API.
Dmitry Volyntsev [Thu, 14 Oct 2021 17:16:10 +0000 (17:16 +0000)]
Modules: fixed Respose.headers getter in fetch API.

The issue manifested itself when Response object is dumped using
JSON.stringify() or njs.dump().  The Response headers were dumped
as "null" values.

4 years agoStyle.
Dmitry Volyntsev [Thu, 14 Oct 2021 15:18:47 +0000 (15:18 +0000)]
Style.

4 years agoSSL: fixed building with OpenSSL <= 1.0.1.
Dmitry Volyntsev [Wed, 13 Oct 2021 16:31:00 +0000 (16:31 +0000)]
SSL: fixed building with OpenSSL <= 1.0.1.

This closes #429 issue on Github.

4 years agoSSL: fixed typo introduced in 8e335c2ac447.
Dmitry Volyntsev [Wed, 13 Oct 2021 15:29:50 +0000 (15:29 +0000)]
SSL: fixed typo introduced in 8e335c2ac447.

4 years agoSSL: fixed compatibility with OpenSSL 3.0.
Dmitry Volyntsev [Tue, 12 Oct 2021 17:24:31 +0000 (17:24 +0000)]
SSL: fixed compatibility with OpenSSL 3.0.

4 years agoIntroduced WebCrypto API according to W3C spec.
Dmitry Volyntsev [Mon, 11 Oct 2021 15:06:15 +0000 (15:06 +0000)]
Introduced WebCrypto API according to W3C spec.

The following methods were implemented:
    crypto.getRandomValues()
    crypto.subtle.importKey()
        format: raw, pkcs8, spki
        algorithm: AES-CBC, AES-CTR, AES-GCM,
            ECDSA, HKDF, HMAC, PBKDF2,
            RSASSA-PKCS1-v1_5, RSA-OAEP, RSA-PSS
    crypto.subtle.decrypt()
    crypto.subtle.encrypt()
        algorithm: AES-CBC, AES-CTR, AES-GCM,
            RSA-OAEP
    crypto.subtle.deriveBits()
    crypto.subtle.deriveKey()
        algorithm: HKDF, PBKDF2
    crypto.subtle.digest()
        algorithm: SHA-1, SHA-256, SHA-384, SHA-512
    crypto.subtle.sign()
    crypto.subtle.verify()
        algorithm: ECDSA, HMAC, RSASSA-PKCS1-v1_5, RSA-PSS

4 years agoFixed copying of closures for declared functions.
Alexander Borisov [Mon, 11 Oct 2021 14:46:24 +0000 (17:46 +0300)]
Fixed copying of closures for declared functions.

After 0a2a0b5a74f4 (0.6.0),  the referencing of a closure value inside of
a nested function may result in heap-use-after-free.  For this to happen
the closure value have to be referenced in a function invoked asynchronously.
For example if a closure value is referenced in r.subrequest() or setTimeout()
handler.

The problem was that closure values of nested function were assigned during
the function call and the memory shared between all the cloned VMs was used
to store temporary assignments until the moment the declared function was
referenced.  When two VMs executed concurrently, the first VM might see
the changed made by the second VM if the first one was suspended.

The fix is to copy all declared functions at the time of the call.

This closes #421 issue on GitHub.

4 years agoTests: added async tests support.
Dmitry Volyntsev [Fri, 8 Oct 2021 13:50:50 +0000 (13:50 +0000)]
Tests: added async tests support.

4 years agoModules: introduced setReturnValue() method.
Dmitry Volyntsev [Fri, 8 Oct 2021 13:41:01 +0000 (13:41 +0000)]
Modules: introduced setReturnValue() method.

4 years agoModules: introduced common ngx_js_retval().
Dmitry Volyntsev [Fri, 8 Oct 2021 13:41:00 +0000 (13:41 +0000)]
Modules: introduced common ngx_js_retval().

4 years agoTypes: updated TS definitions.
Dmitry Volyntsev [Fri, 8 Oct 2021 13:40:58 +0000 (13:40 +0000)]
Types: updated TS definitions.

4 years agoFixed unhandled promise rejection in handle events.
Alexander Borisov [Fri, 8 Oct 2021 09:32:42 +0000 (12:32 +0300)]
Fixed unhandled promise rejection in handle events.

This closes #423 issue on GitHub.

4 years agoStyle.
Dmitry Volyntsev [Wed, 6 Oct 2021 13:16:09 +0000 (13:16 +0000)]
Style.

4 years agoFixed timeouts with Fetch, SSL and select.
Sergey Kandaurov [Wed, 6 Oct 2021 12:57:14 +0000 (15:57 +0300)]
Fixed timeouts with Fetch, SSL and select.

Similar to the connection hang fixed in 058a67435e83 in nginx,
it is possible that an established connection is ready for reading
after the handshake.  Further, events might be already disabled
in case of level-triggered event methods.

Fix is to post a read event if the c->read->ready flag is set.

4 years agoAdded support for HTTPS URLs to the Fetch API.
Antoine Bonavita [Wed, 1 Sep 2021 18:43:56 +0000 (20:43 +0200)]
Added support for HTTPS URLs to the Fetch API.

The fetch API now accepts an extra parameters:
    - verify: boolean (default true) to control server certificate
    verification.

Verification process can be controlled with the following directives
from the http js and stream js modules:
    - js_fetch_ciphers
    - js_fetch_protocols
    - js_fetch_verify_depth
    - js_fetch_trusted_certificate

In collaboration with Dmitry Volyntsev.

4 years agoModules: simplified reporting of failures in ngx.fetch() method.
Dmitry Volyntsev [Tue, 5 Oct 2021 13:01:11 +0000 (13:01 +0000)]
Modules: simplified reporting of failures in ngx.fetch() method.

4 years agoTests: introducing repeat argument for unit tests.
Dmitry Volyntsev [Wed, 29 Sep 2021 16:13:36 +0000 (16:13 +0000)]
Tests: introducing repeat argument for unit tests.

4 years agoFixed function constructor for cloned VMs.
Dmitry Volyntsev [Wed, 29 Sep 2021 13:45:26 +0000 (13:45 +0000)]
Fixed function constructor for cloned VMs.

Previously a shared "keywords_hash" and "values_hash" were used while
compiling functions in runtime.  This led to populating a shared hash
with elements allocated in a cloned VM.  Which resulted in
heap-use-after-free when next cloned VM accesses the shared hashes.

4 years agoFixed njs_buffer_slot().
Dmitry Volyntsev [Fri, 17 Sep 2021 18:29:40 +0000 (18:29 +0000)]
Fixed njs_buffer_slot().

Previously, njs_buffer_slot() might return NULL value without setting
corresponding exception where user code expects it.

In addition the function is split into two functions.  The internal one
does not set anything to vm->retval.  This function has to be used by
property handlers, because they are expected not to modify vm->retval.