GeezerVison is showing github.com — src: add buildflag to force context-aware addons · jmdfm/node@3c17f16
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +8Lines changed: 8 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -411,6 +411,13 @@ added: v6.0.0 | 411 | 411 |
| 412 | 412 | Silence all process warnings (including deprecations). | 413 | 413 |
| | 414 | +### `--force-context-aware` | | 415 | +<!-- YAML | | 416 | +added: REPLACEME | | 417 | +--> | | 418 | + | | 419 | +Disable loading non-context-aware native addons. | | 420 | + | 414 | 421 | ### `--openssl-config=file` | 415 | 422 | <!-- YAML | 416 | 423 | added: v6.9.0 | @@ -980,6 +987,7 @@ Node.js options that are allowed are: | 980 | 987 | * `--experimental-report` | 981 | 988 | * `--experimental-vm-modules` | 982 | 989 | * `--experimental-wasm-modules` | | 990 | +* `--force-context-aware` | 983 | 991 | * `--force-fips` | 984 | 992 | * `--frozen-intrinsics` | 985 | 993 | * `--heapsnapshot-signal` | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/errors.md +5Lines changed: 5 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1611,6 +1611,11 @@ OpenSSL crypto support. | 1611 | 1611 | An attempt was made to use features that require [ICU][], but Node.js was not | 1612 | 1612 | compiled with ICU support. | 1613 | 1613 |
| | 1614 | +<a id="ERR_NON_CONTEXT_AWARE_DISABLED"></a> | | 1615 | +### ERR_NON_CONTEXT_AWARE_DISABLED | | 1616 | + | | 1617 | +A non-context-aware native addon was loaded in a process that disallows them. | | 1618 | + | 1614 | 1619 | <a id="ERR_OUT_OF_RANGE"></a> | 1615 | 1620 | ### ERR_OUT_OF_RANGE | 1616 | 1621 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_binding.cc +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #include "node_binding.h" | | 2 | +#include "node_errors.h" | 2 | 3 | #include <atomic> | 3 | 4 | #include "env-inl.h" | 4 | 5 | #include "node_native_module_env.h" | @@ -462,6 +463,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { | 462 | 463 | } | 463 | 464 |
| 464 | 465 | if (mp != nullptr) { | | 466 | + if (mp->nm_context_register_func == nullptr) { | | 467 | + if (env->options()->force_context_aware) { | | 468 | + dlib->Close(); | | 469 | + THROW_ERR_NON_CONTEXT_AWARE_DISABLED(env); | | 470 | + return false; | | 471 | + } | | 472 | + } | 465 | 473 | mp->nm_dso_handle = dlib->handle_; | 466 | 474 | dlib->SaveInGlobalHandleMap(mp); | 467 | 475 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_errors.h +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,6 +52,7 @@ void PrintErrorString(const char* format, ...); | 52 | 52 | V(ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST, TypeError) \ | 53 | 53 | V(ERR_MISSING_PASSPHRASE, TypeError) \ | 54 | 54 | V(ERR_MISSING_PLATFORM_FOR_WORKER, Error) \ | | 55 | + V(ERR_NON_CONTEXT_AWARE_DISABLED, Error) \ | 55 | 56 | V(ERR_MODULE_NOT_FOUND, Error) \ | 56 | 57 | V(ERR_OUT_OF_RANGE, RangeError) \ | 57 | 58 | V(ERR_SCRIPT_EXECUTION_INTERRUPTED, Error) \ | @@ -96,6 +97,8 @@ void PrintErrorString(const char* format, ...); | 96 | 97 | V(ERR_MISSING_PLATFORM_FOR_WORKER, \ | 97 | 98 | "The V8 platform used by this instance of Node does not support " \ | 98 | 99 | "creating Workers") \ | | 100 | + V(ERR_NON_CONTEXT_AWARE_DISABLED, \ | | 101 | + "Loading non context-aware native modules has been disabled") \ | 99 | 102 | V(ERR_SCRIPT_EXECUTION_INTERRUPTED, \ | 100 | 103 | "Script execution was interrupted by `SIGINT`") \ | 101 | 104 | V(ERR_TRANSFERRING_EXTERNALIZED_SHAREDARRAYBUFFER, \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -385,6 +385,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 385 | 385 | "silence all process warnings", | 386 | 386 | &EnvironmentOptions::no_warnings, | 387 | 387 | kAllowedInEnvironment); | | 388 | + AddOption("--force-context-aware", | | 389 | + "disable loading non-context-aware addons", | | 390 | + &EnvironmentOptions::force_context_aware, | | 391 | + kAllowedInEnvironment); | 388 | 392 | AddOption("--pending-deprecation", | 389 | 393 | "emit pending deprecation warnings", | 390 | 394 | &EnvironmentOptions::pending_deprecation, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,6 +116,7 @@ class EnvironmentOptions : public Options { | 116 | 116 | bool no_deprecation = false; | 117 | 117 | bool no_force_async_hooks_checks = false; | 118 | 118 | bool no_warnings = false; | | 119 | + bool force_context_aware = false; | 119 | 120 | bool pending_deprecation = false; | 120 | 121 | bool preserve_symlinks = false; | 121 | 122 | bool preserve_symlinks_main = false; | |
|