Commit Graph

260 Commits

Author SHA1 Message Date
Hüseyin Açacak
7f68e5466a
path,win: fix bug in resolve and normalize
Fixes: https://github.com/nodejs/node/issues/54025
PR-URL: https://github.com/nodejs/node/pull/55623
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-05 23:21:54 +00:00
Aviv Keller
ee46d2297c
Revert "path: fix bugs and inconsistencies"
This reverts commit efbba60e5b.

PR-URL: https://github.com/nodejs/node/pull/55414
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-10-21 07:10:47 +00:00
minkyu_kim
b57977909a
test: update test_util.cc for coverage
update test_util.cc for code coverage src/util-inl.h:PopFront()

PR-URL: https://github.com/nodejs/node/pull/55291
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-10-14 06:41:27 +00:00
Hüseyin Açacak
efbba60e5b
path: fix bugs and inconsistencies
Fixes: https://github.com/nodejs/node/issues/54025
PR-URL: https://github.com/nodejs/node/pull/54224
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2024-09-14 14:56:31 +00:00
Joyee Cheung
0be79f4deb
src: remove dependency on wrapper-descriptor-based CppHeap
As V8 has moved away from wrapper-descriptor-based CppHeap, this
patch:

1. Create the CppHeap without using wrapper descirptors.
2. Deprecates node::SetCppgcReference() in favor of
   v8::Object::Wrap() since the wrapper descriptor is no longer
   relevant. It is still kept as a compatibility layer for addons
   that need to also work on Node.js versions without
   v8::Object::Wrap().

PR-URL: https://github.com/nodejs/node/pull/54077
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-16 16:04:35 +02:00
James M Snell
d335487e3f src, deps: add nbytes library
Projects that seek to implement Node.js compatible APIs end up
needed to reproduce various bits of functionality internally in
order to faithfully replicate the Node.js behaviors. This is
particularly true for things like byte manipulation, base64 and
hex encoding, and other low-level operations. This change
proposes moving much of this low-level byte manipulation code
out of nodejs/src and into a new `nbytes` library. Initially this
new library will exist in the `deps` directory but the intent is
to spin out a new separate repository to be its home in the future.
Doing so will allow other projects to use the nbytes library with
exactly the same implementation as Node.js.

This commit moves only the byte swapping and legacy base64 handling
code. Additional commits will move additional byte manipulation
logic into the library.

PR-URL: https://github.com/nodejs/node/pull/53507
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-06-21 07:38:37 -07:00
Yagiz Nizipli
399eb338f1
fs: move ToNamespacedPath to c++
Co-Authored-By: Daniel Lemire <daniel@lemire.me>
PR-URL: https://github.com/nodejs/node/pull/52135
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-06-20 02:11:10 +00:00
Adam Klein
a6d54f179d src: remove calls to recently deprecated V8 APIs
Closes: https://github.com/nodejs/node/issues/52991
PR-URL: https://github.com/nodejs/node/pull/52996
Fixes: https://github.com/nodejs/node/issues/52991
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-05-19 09:12:40 +00:00
Yagiz Nizipli
fe4e569759
src: fix positional args in task runner
PR-URL: https://github.com/nodejs/node/pull/52810
Fixes: https://github.com/nodejs/node/issues/52740
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-05-08 11:37:07 +00:00
Yagiz Nizipli
c5cfdd4849
src: rewrite task runner in c++
PR-URL: https://github.com/nodejs/node/pull/52609
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-05-02 19:54:02 +00:00
Daniel Lemire
6aa9047f96
deps,src: simplify base64 encoding
PR-URL: https://github.com/nodejs/node/pull/52714
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2024-04-30 06:39:12 +00:00
James M Snell
06a3a2a1fb quic: rework TLSContext, additional cleanups
PR-URL: https://github.com/nodejs/node/pull/51340
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-04-20 18:10:17 -07:00
Cheng Zhao
b34512e38e
src: preload function for Environment
This PR adds a |preload| arg to the node::LoadEnvironment to allow
embedders to set a preload function for the environment, which will run
after the environment is loaded and before the main script runs.

This is similiar to the --require CLI option, but runs a C++ function,
and can only be set by embedders.

The preload function can be used by embedders to inject scripts before
running the main script, for example:
1. In Electron it is used to initialize the ASAR virtual filesystem,
   inject custom process properties, etc.
2. In VS Code it can be used to reset the module search paths for
   extensions.

PR-URL: https://github.com/nodejs/node/pull/51539
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
2024-03-04 02:41:18 +00:00
Rafael Gonzaga
338a5be272
lib,src,permission: port path.resolve to C++
Co-Authored-By: Carlos Espa <cespatorres@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/50758
Refs: https://github.com/nodejs/security-wg/issues/898
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
2023-12-30 13:46:27 +00:00
James M Snell
c3664227a8 quic: add quic internalBinding, refine Endpoint, add types
PR-URL: https://github.com/nodejs/node/pull/51112
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-12-26 16:27:49 -08:00
Chengzhong Wu
a81788cb27
node-api: type tag external values without v8::Private
v8::External can not have any properties and private properties. Type
tag v8::External with a wrapper struct without setting a private
property on the v8::External.

PR-URL: https://github.com/nodejs/node/pull/51149
Fixes: https://github.com/nodejs/node-v8/issues/273
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com>
2023-12-22 09:34:51 +00:00
Yagiz Nizipli
65e70bf54e
fs: validate fd synchronously on c++
PR-URL: https://github.com/nodejs/node/pull/51027
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-12-18 22:06:45 +00:00
Joyee Cheung
429ec83e1b vm: use v8::DeserializeInternalFieldsCallback explicitly
To avoid ambiguity in the signature.

PR-URL: https://github.com/nodejs/node/pull/50984
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-12-14 16:38:02 +01:00
Joyee Cheung
036c89f917
src: use v8::Isolate::TryGetCurrent() in DumpJavaScriptBacktrace()
It was using Isolate::GetCurrent() which DCHECK on nullptr, even
though what we wanted was to return early if it is nullptr.

PR-URL: https://github.com/nodejs/node/pull/50518
Refs: https://github.com/nodejs/node/pull/50242
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-11-06 09:25:06 +00:00
Tobias Nießen
6117cc3bd1
test: fix compiler warning in NodeCryptoEnv
This fixes a warning in line 26: "warning: value computed is not used"
when calling BIO_seek().

Refs: https://github.com/nodejs/node/pull/47160
PR-URL: https://github.com/nodejs/node/pull/49206
Reviewed-By: Michael Dawson <midawson@redhat.com>
2023-08-24 16:25:09 +00:00
Joyee Cheung
b68fa59960
src: use effective cppgc wrapper id to deduce non-cppgc id
Previously we hard-code a wrapper id to be used in BaseObjects
to avoid accidentally triggering cppgc on these non-cppgc-managed
objects, but hard-coding can be be hacky and result in mismatch
when we start to create CppHeap ourselves. This patch makes it
more robust by deducing non-cppgc id from the effective cppgc id,
if there is one.

PR-URL: https://github.com/nodejs/node/pull/48660
Refs: 9327503128
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2023-07-21 16:44:23 +02:00
Chengzhong Wu
c47ea21685
bootstrap: hide experimental web globals with flag kNoBrowserGlobals
Do not install experimental web globals when the environment is
initialized with embedder flag
`node::EnvironmentFlags::kNoBrowserGlobals`.

PR-URL: https://github.com/nodejs/node/pull/48545
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-07-05 07:02:59 +00:00
Joyee Cheung
42d8143ce5
test: make IsolateData per-isolate in cctest
This ensures that we only create one IsolateData for each isolate
inthe cctest, since IsolateData are meant to be per-isolate.
We need to make the isolate and isolate_data static in the
test fixtures as a result, similar to how the event loops and
array buffer allocators are managed in the
NodeZeroIsolateTestFixture but it is fine because gtest ensures
that the Setup() and TearDown() of the fixtures are always run
in order and would never overlap in one process.

PR-URL: https://github.com/nodejs/node/pull/48450
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-06-25 05:41:19 +00:00
Chengzhong Wu
e7a1fab25f
test: define NAPI_VERSION before including node_api.h
Include node.h first to define NAPI_VERSION that node binary is built
with. The node.h should also be included first in embedder's use case
since it is the primary header file.

PR-URL: https://github.com/nodejs/node/pull/48376
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2023-06-24 17:04:08 +00:00
GauriSpears
10b21e5685
crypto: use openssl's own memory BIOs in crypto_context.cc
NodeBIO's memory buffer structure does not support BIO_C_FILE_SEEK and B
IO_C_FILE_TELL. This prevents OpenSSL PEM_read_bio_PrivateKey from readi
ng some private keys. So I switched to OpenSSL'w own protected memory bu
ffers.

Fixes: https://github.com/nodejs/node/issues/47008
PR-URL: https://github.com/nodejs/node/pull/47160
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-05-18 16:28:44 +00:00
Vladimir Morozov
c542d3a1d3 node-api: get Node API version used by addon
PR-URL: https://github.com/nodejs/node/pull/45715
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-05-05 11:00:27 -04:00
Mohammed Keyvanzadeh
dd6eb67b1f
src: prefer data accessor of string and vector
The pattern of getting the address of the element at index 0 of a
container is generally used to materialize a pointer to the backing
data of a container, however `std::string` and `std::vector`
provide a `data()` accessor to retrieve the data pointer which
should be preferred.

This also ensures that in the case that the container is empty, the
data pointer access does not perform an errant memory access.

PR-URL: https://github.com/nodejs/node/pull/47750
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-05-03 14:09:23 +00:00
James M Snell
d65ae9f678 quic: add additional quic implementation utilities
* add TokenSecret, StatelessResetToken, RetryToken, and RegularToken
* add SessionTicket implementation

PR-URL: https://github.com/nodejs/node/pull/47289
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2023-03-31 09:58:37 -07:00
James M Snell
09a4bb152f quic: add multiple internal utilities
* add the CID implementation
* add the PreferredAddress implementation
* add Path and PathStorage implementations
* add Store implementation
* add QuicError implementation

PR-URL: https://github.com/nodejs/node/pull/47263
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-03-28 17:15:59 -07:00
Vladimir Morozov
5e4f5e122c node-api: deprecate napi_module_register
PR-URL: https://github.com/nodejs/node/pull/46319
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2023-03-24 14:00:40 -04:00
Joyee Cheung
8b2126f63f
src: move AliasedBuffer implementation to -inl.h
Drive-by: Replace the SFINAE with a static_assert because we don't
have (or need) an implementation for non-scalar AliasedBufferBase
otherwise. Add forward declarations to memory_tracker.h now that
aliased-buffer.h no longer includes util-inl.h.

PR-URL: https://github.com/nodejs/node/pull/46817
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-03-01 17:45:02 +01:00
James M Snell
71fb06fd64 src, lib: fixup lint and format issues for DataQueue/Blob
Co-authored-by: flakey5 <73616808+flakey5@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/45258
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-02-19 16:26:59 -08:00
James M Snell
950cec4c26 src: update Blob implementation to use DataQueue / File-backed Blobs
Co-authored-by: flakey5 <73616808+flakey5@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/45258
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-02-19 16:26:58 -08:00
Yagiz Nizipli
c4581abff6 url: replace url-parser with ada
PR-URL: https://github.com/nodejs/node/pull/46410
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2023-02-06 19:21:39 +00:00
Yagiz Nizipli
85f9b27c14
url: remove unused URL::ToFilePath()
PR-URL: https://github.com/nodejs/node/pull/46487
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-05 15:30:22 +00:00
Yagiz Nizipli
95c064d46e src: fix endianness of simdutf
PR-URL: https://github.com/nodejs/node/pull/46257
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-01-18 23:50:35 +00:00
Anna Henningsen
d896f5befd
src: make BuiltinLoader threadsafe and non-global
As discussed in https://github.com/nodejs/node/pull/45888, using a
global `BuiltinLoader` instance is probably undesirable in a world
in which embedders are able to create Node.js Environments with
different sources and therefore mutually incompatible code
caching properties.

This PR makes it so that `BuiltinLoader` is no longer a global
singleton and instead only shared between `Environment`s that
have a direct relation to each other, and addresses a few
thread safety issues along with that.

PR-URL: https://github.com/nodejs/node/pull/45942
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-01-18 22:03:00 +00:00
Anna Henningsen
21fb98e2bf
src: use simdutf for converting externalized builtins to UTF-16
Remove the dependency on ICU for this part, as well as the
hacky way of converting embedder main sources to UTF-8 via
V8 APIs. Allow `UnionBytes` to own the memory its pointing
to in order to simplify the code on the `BuiltinLoader` side.

PR-URL: https://github.com/nodejs/node/pull/46119
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-01-10 11:25:19 +00:00
ywave620
8438f3b73b
process,worker: ensure code after exit() effectless
Cope with the delay(to the next function call) of
v8::Isolate::TerminateExecution()

PR-URL: https://github.com/nodejs/node/pull/45620
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-12-25 09:54:12 +00:00
legendecas
f14fa1bbca
node-api: generalize finalizer second pass callback
Generalize the finalizer's second pass callback to make it
cancellable and simplify the code around the second pass callback.

With this change, it is determined that Reference::Finalize or
RefBase::Finalize are called once, either from the env's shutdown,
or from the env's second pass callback.

All existing node-api js tests should pass without a touch. The
js_native_api cctest is no longer applicable with this change,
just removing it.

PR-URL: https://github.com/nodejs/node/pull/44141
Refs: https://github.com/nodejs/node/issues/44071
Reviewed-By: Michael Dawson <midawson@redhat.com>
2022-12-20 01:44:42 +08:00
Tobias Nießen
4124b03774 inspector: harden IP address validation again
Use inet_pton() to parse IP addresses, which restricts IP addresses
to a small number of well-defined formats. In particular, octal and
hexadecimal number formats are not allowed, and neither are leading
zeros. Also explicitly reject 0.0.0.0/8 and ::/128 as non-routable.

Refs: https://hackerone.com/reports/1710652
CVE-ID: CVE-2022-43548
PR-URL: https://github.com/nodejs-private/node-private/pull/354
Reviewed-by: Michael Dawson <midawson@redhat.com>
Reviewed-by: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-by: Rich Trott <rtrott@gmail.com>
2022-11-04 14:56:31 -03:00
Tobias Nießen
fcf27b12e3 test: use CHECK instead of EXPECT where necessary
GetPageSize() and OverrunGuardedBuffer currently use non-fatal EXPECT_*
macros because GoogleTest does not allow the fatal variants ASSERT_* in
non-void returning functions (i.e., in this file, nowhere outside of the
TEST itself).

The EXPECT_* macros continue execution upon failure, but we really don't
want that (and static analysis apparently does not like it either).
Since we cannot use GoogleTest's ASSERT_* here, use our own CHECK_*
instead of EXPECT_* outside of the TEST. Hopefully, this will finally
pacify static analysis.

Refs: https://github.com/nodejs/node/pull/44666

PR-URL: https://github.com/nodejs/node/pull/44795
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2022-10-14 14:10:48 -04:00
Clemens Backes
2e49b99cc2
src,test: disable freezing V8 flags on initialization
Node.js still changes flags after initializationg; either because
tests need to set their own flags (which V8 tests also still allow),
or because it's explicitly requested via the "v8.setFlagsFromString"
method that Node.js provides.

PR-URL: https://github.com/nodejs/node/pull/44741
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-10-11 07:27:32 +02:00
Michaël Zasso
fd52c62bee
src: use V8_ENABLE_SANDBOX macro
It was renamed from V8_SANDBOX

PR-URL: https://github.com/nodejs/node/pull/44741
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-10-11 07:27:27 +02:00
Tobias Nießen
1af661908f
src: remove UncheckedMalloc(0) workaround
Assuming that UncheckedMalloc(0) returns a non-nullptr is non-standard
and we use other allocators as well (e.g., OPENSSL_malloc) that do not
guarantee this behavior. It is the caller's responsibility to check that
size != 0 implies UncheckedMalloc(size) != nullptr, and that's exactly
what the checked variants (Malloc etc.) already do.

The current behavior is also inconsistent with UncheckedRealloc(), which
always returns a nullptr when the size is 0, and with the documentation
in src/README.md as well as with multiple comments in the source code.

This changes UncheckedMalloc(), UncheckedCalloc(), and
UncheckedRealloc() to always return a nullptr when the size is 0 instead
of doing fake allocations in UncheckedMalloc() and UncheckedCalloc()
while returning a nullptr from UncheckedRealloc(). This is consistent
with existing documentation and comments.

Refs: https://github.com/nodejs/node/issues/8571
Refs: https://github.com/nodejs/node/pull/8572
PR-URL: https://github.com/nodejs/node/pull/44543
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-10-05 15:39:27 +00:00
Chengzhong Wu
717465433c src: create BaseObject with node::Realm
BaseObject is a wrapper around JS objects. These objects should be
created in a node::Realm and destroyed when their associated realm is
cleaning up.

PR-URL: https://github.com/nodejs/node/pull/44348
Refs: https://github.com/nodejs/node/issues/42528
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2022-09-27 16:39:53 +08:00
Tobias Nießen
3492320fdd
test: check that sysconf returns a positive value
Static analysis insists that sysconf(_SC_PAGE_SIZE) might return a
negative integer (even though it never will). This was supposed to be
handled by the existing check EXPECT_GE(page, static_cast<int>(N)).
I assume that static analysis does not consider this sufficient because
static_cast<int>(N) could be negative or zero if N exceeds INT_MAX (even
though it never will).

To resolve this (theoretical) problem, explicitly check that the return
value is positive and then cast it to a size_t.

PR-URL: https://github.com/nodejs/node/pull/44666
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2022-09-25 10:30:37 +00:00
RafaelGSS
b358fb27a4 src: fix IPv4 non routable validation
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
PR-URL: https://github.com/nodejs-private/node-private/pull/337
CVE-ID: CVE-2022-32212, CVE-2018-7160
2022-09-23 12:32:45 -03:00
Tobias Nießen
a47c2c58ae
tls: fix out-of-bounds read in ClientHelloParser
ClientHelloParser::ParseHeader(data, avail) potentially accesses data
beyond avail bytes because it trusts the client to transmit a valid
frame length. Sending an impossibly small frame length causes the TLS
server to read beyond the buffer provided by the caller.

Guard against this by calling End() on the ClientHelloParser when the
client transmits an impossibly small frame length.

The test is designed to reliable cause a segmentation fault on Linux and
Windows when the buffer overrun occurs, and to trigger a spatial safety
violation when compiled with an address sanitizer enabled or when
running under valgrind.

PR-URL: https://github.com/nodejs/node/pull/44580
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2022-09-15 17:27:04 +00:00
Daniel Bevenius
0cdf0348ec test: fix DebugSymbolsTest.ReqWrapList on PPC64LE
Currently, DebugSymbolsTest.ReqWrapList fails on PPC64LE when Node has
been configured with Link Time Optimization (LTO) and using RHEL 8.5
and gcc:
```console
$ . /opt/rh/gcc-toolset-11/enable
$ export CC='ccache gcc'
$ export CXX='ccache g++'
$ ./configure --enable-lto
$ make -j8 cctest
...
21:52:27 [ RUN      ] DebugSymbolsTest.ReqWrapList
21:52:27 ../test/cctest/test_node_postmortem_metadata.cc:203: Failure
21:52:27 Expected equality of these values:
21:52:27   expected
21:52:27     Which is: 140736537072320
21:52:27   calculated
21:52:27     Which is: 1099680328560
21:52:27 [  FAILED  ] DebugSymbolsTest.ReqWrapList (43 ms)
```

After looking into this is seems that the compiler is tampering with the
`last` variable when compiling with LTO enabled. This commit suggests
adding volatile to this variable to prevent the compiler from tampering
with it.

PR-URL: https://github.com/nodejs/node/pull/44341
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2022-09-06 10:06:42 +02:00