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.
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.
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.
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.
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
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.
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.
Dmitry Volyntsev [Tue, 31 Aug 2021 13:16:32 +0000 (13:16 +0000)]
Fixed backtrace output for arrays broken in b0177571ce1d.
After the previous commit the array prototype methods were not found
during njs_object_traverse() invocation. As the result the exceptions in
Array.prototype methods were reported with a backtrace containing "native
(native)" instead of a proper function name.
Miao Wang [Wed, 11 Aug 2021 03:44:12 +0000 (11:44 +0800)]
Stream: fixed CPU hog when js_filter is registered in both directions.
Previously, a single busy chain was used to track filtered data in both
directions. This might lead to a situation when busy chunks are not
freed properly and pile up.
The fix is to separate busy chain for upstream and downstream directions.
Marking different external pointer with unique tag.
An external value has an arbitrary raw pointer associated with it.
External values with different prototypes have different C-level
structures. To ensure that only appropriate structures are fetched
by njs_vm_external() the unique tag has to be provided during
creation of external values.
Dmitry Volyntsev [Fri, 25 Jun 2021 17:00:12 +0000 (17:00 +0000)]
Fixed RegExpBuiltinExec() with UTF-8 only regexps.
The original issue was introduced in f9082cd59ba6 (0.4.2) while adding
RegExpBuiltinExec(), but after de64420d0f2b (0.6.0) it started to affect
RegExp.prototype.test() as it was rewritten according to spec.