src/qjs.c:347:19: error: variable 'signo' may be uninitialized when used
here [-Werror,-Wconditional-uninitialized]
347 | if (kill(pid, signo) < 0) {
| ^~~~~
src/qjs.c:294:31: note: initialize the variable 'signo' to silence this
warning
294 | int signo, pid;
| ^
| = 0
1 error generated.
Dmitry Volyntsev [Sat, 19 Oct 2024 01:24:49 +0000 (18:24 -0700)]
Improved error messages for module loading failures.
There are several reasons why a file cannot be opened. Without
extra information, especially in containerized environments, these
problems are difficult to debug. Adding errno status to the
error output helps identify the root cause.
Additionally, error messages are now aligned between njs and QuickJS.
Dmitry Volyntsev [Wed, 16 Oct 2024 01:28:19 +0000 (18:28 -0700)]
Implemented lazy stack symbolization.
Previously, when an exception was thrown, the exception got 'stack'
property attached which contained the backtrace information about where
the exception happened. This could be a heavy operation and it was not
always needed.
To optimize it, the process is split into 2 phases. The first phase
collects all the necessary info about the current stack. The second
phase, where the stack symbolization happens, occurs only when this
property is referenced.
Dmitry Volyntsev [Sat, 12 Oct 2024 00:23:42 +0000 (17:23 -0700)]
Modules: removed extra VMs creation when it is not needed.
Previously, a new VM instance was created for every location. This is
not needed and consumes a lot of memory for large configurations.
Instead, if no new js_import is introduced on the location level server
level VM should be used.
Dmitry Volyntsev [Thu, 10 Oct 2024 00:32:11 +0000 (17:32 -0700)]
Fixed heap-buffer-overflow in Buffer.prototype.indexOf().
Previously, when `from` argument was provided heap-buffer-overflow might
happen due to lack of boundary check. `to = njs_min(to, length)`
statement was also removed because it has no effect, `to` is
equal to `length` here.
Dmitry Volyntsev [Sat, 15 Jun 2024 03:54:28 +0000 (20:54 -0700)]
Modules: introduced QuickJS engine.
"js_engine" directive is introduced which sets JavaScript engine.
When the module is built with QuickJS library "js_engine qjs;" sets
QuickJS engine for the current block. By default njs engine is used.
For example,
nginx.conf:
location /a {
js_engine qjs;
# will be handled by QuickJS
js_content main.handler;
}
location /b {
# will be handled by njs
js_content main.handler;
}
QuickJS engine implements drop-in replacement for nginx/njs objects
with the following exceptions:
* nginx module API to be added later: ngx.fetch(), ngx.shared.dict.
* Built-in modules to be added later: fs, crypto, WebCrypto, xml.
* NJS specific API: njs.dump(), njs.on(), console.dump().
* js_preload_object directive.
QuickJS: disabling eval() and Function() in qjs_new_context().
This properly disables eval() after previous attempt in c773ebcaad
(0.8.5). In QuickJS buint-in C level eval API, which is used by njs, is
linked to eval() in JS code. To disable only the JS function
manual modification of global object is required.
Thomas P. [Wed, 7 Aug 2024 09:47:08 +0000 (11:47 +0200)]
Modules: added nocache flag for js_set variables.
This commit adds support for an additional `nocache` flag in `js_set`
directives. If set, the resulting nginx variable will have no_cacheable set
to 1. This enables us to dynamically recompute a variable if the context
changed (for example, in case of an internal redirection).
In case of multiple calls in a location, users should cache the result in a
rewrite variable: `set $cached_variable $js_variable;`
Elijah Zupancic [Tue, 20 Aug 2024 18:41:44 +0000 (11:41 -0700)]
Add badges to README.md
This change adds two badges indicating the current project status and level of
support offered. These badges are standardized across many nginx projects.
Dmitry Volyntsev [Fri, 21 Jun 2024 00:11:24 +0000 (17:11 -0700)]
Fixed maybe-uninitialized warning in error creation.
Ensuring that buf is always initialized in njs_throw_error_va()
and njs_error_fmt_new(), by requiring fmt to always be non NULL.
This fixes GCC warnings like:
169 | njs_unicode_decode_t ctx;
| ^
In function ‘njs_utf8_length’,
inlined from ‘njs_error_new’ at src/njs_error.c:39:14,
inlined from ‘njs_throw_error_va’ at src/njs_error.c:69:5:
src/njs_utf8.h:141:12: error: ‘buf’ may be used uninitialized
[-Werror=maybe-uninitialized]
141 | return njs_utf8_stream_length(&ctx, p, len, 1, 1, NULL);
Dmitry Volyntsev [Sat, 22 Jun 2024 00:58:32 +0000 (17:58 -0700)]
Fixed ‘ctx.codepoint’ may be used uninitialized.
When building by GCC 13 with -O3 and -flto flags the following
warning was reported:
In function ‘njs_utf8_decode’,
inlined from ‘njs_text_encoder_encode_into’ at
src/njs_encoding.c:214:14:
src/njs_utf8.c:191:42: error: ‘ctx.codepoint’ may be used
uninitialized [-Werror=maybe-uninitialized]
191 | ctx->codepoint = (ctx->codepoint << 6) | (c & 0x3F);
Dmitry Volyntsev [Fri, 21 Jun 2024 00:26:14 +0000 (17:26 -0700)]
Fixed ‘length’ may be used uninitialized in Array.prototype.pop().
When building by GCC with -O3 and -flto flags the following
warning was reported:
src/njs_array.c: In function ‘njs_array_prototype_pop’:
src/njs_array.c:1009:8: error: ‘length’ may be used uninitialized in
this function [-Werror=maybe-uninitialized]
1009 | if (length == 0) {
| ^
Returning a specific code in njs_value_to_number() helps GCC
to infer that there are only 2 return values are possible and
both of them are handled.
Dmitry Volyntsev [Fri, 31 May 2024 05:22:48 +0000 (22:22 -0700)]
HTTP: fixed r.subrequest() error handling.
Previously, when at least 2 subrequests were scheduled they both
succeed, but the callback for the second threw an exception
heap-use-after-free happened: a nested chain of
ngx_http_run_posted_requests() calls and terminating request in the
inner call left outer calls with already freed request pointer.
The optional timeout argument overrides the timeout specified with
the shared_dict_zone directive for the effected key and operation
only. The timeout is specified in milliseconds.
This is useful when the majority of keys are expected to require
unique timeouts.
Dmitry Volyntsev [Thu, 30 May 2024 05:23:55 +0000 (22:23 -0700)]
Test262: fixed flaky fs tests.
Previously, two tests running in parallel could occasionally generate
identical file names because Math.random() was used for part of the file
name, leading to one of the tests failing.
The fix is to use a single global counter to generate file names,
ensuring deterministic and unique file names for each test.